Skip to contentSkip to conversation

hw/ppc: Set QDev properties using QDev API (part 2/3)

PATCH In review Philippe Mathieu-Daudé 5 participants 17 messages Feb 3, 2023 – Feb 6, 2023

lore
Share & tools
lore
#0 lore raw

cover hw/ppc: Set QDev properties using QDev API (part 2/3)

part 1 [*] cover:
--
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. --

In this series PPC hw is converted. Only one call site in PNV forwards the Error* argument and its conversion is justified.

Based-on: <[email protected]>
(in particular [PATCH 02/19] hw/qdev: Introduce qdev_prop_set_link():
https://lore.kernel.org/qemu-devel/[email protected]/)

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (5):
hw/misc/macio: Set QDev properties using QDev API hw/pci-host/raven: Set QDev properties using QDev API hw/ppc/ppc4xx: Set QDev properties using QDev API hw/ppc/spapr: Set QDev properties using QDev API hw/ppc/pnv: Set QDev properties using QDev API

 hw/intc/pnv_xive.c         | 11 ++++------
 hw/intc/pnv_xive2.c        | 15 +++++---------
 hw/intc/spapr_xive.c       | 11 ++++------
 hw/intc/xics.c             |  4 ++--
 hw/intc/xive.c             |  4 ++--
 hw/misc/macio/macio.c      |  6 ++----
 hw/pci-host/pnv_phb3.c     |  9 +++------
 hw/pci-host/pnv_phb4.c     |  4 ++--
 hw/pci-host/pnv_phb4_pec.c | 10 +++-------
 hw/pci-host/raven.c        |  6 ++----
 hw/ppc/e500.c              |  3 +--
 hw/ppc/pnv.c               | 41 ++++++++++++++++----------------------
 hw/ppc/pnv_psi.c           | 10 +++-------
 hw/ppc/ppc405_boards.c     |  6 ++----
 hw/ppc/ppc405_uc.c         |  6 +++---
 hw/ppc/ppc440_bamboo.c     |  3 +--
 hw/ppc/ppc4xx_devs.c       |  2 +-
 hw/ppc/sam460ex.c          |  5 ++---
 hw/ppc/spapr_irq.c         |  8 +++-----
 19 files changed, 62 insertions(+), 102 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/5 hw/misc/macio: Set QDev properties using QDev API

No need to use the low-level QOM API when an object inherits from QDev. Directly use the QDev API to set its properties.

All calls use errp=&error_abort, so converting to the QDev API is a no-op (QDev API always uses &error_abort).

---
 hw/misc/macio/macio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/misc/macio/macio.c +2 -4
index 08dbdd7fc0..66393280f1 100644
@@ -128,8 +128,7 @@ static void macio_realize_ide(MacIOState *s, MACIOIDEState *ide,
     sysbus_connect_irq(sysbus_dev, 0, irq0);
     sysbus_connect_irq(sysbus_dev, 1, irq1);
     qdev_prop_set_uint32(DEVICE(ide), "channel", dmaid);
-    object_property_set_link(OBJECT(ide), "dbdma", OBJECT(&s->dbdma),
-                             &error_abort);
+    qdev_prop_set_link(DEVICE(ide), "dbdma", OBJECT(&s->dbdma));
     macio_ide_register_dma(ide);
 
     qdev_realize(DEVICE(ide), BUS(&s->macio_bus), errp);
@@ -336,8 +335,7 @@ static void macio_newworld_realize(PCIDevice *d, Error **errp)
 
         /* PMU */
         object_initialize_child(OBJECT(s), "pmu", &s->pmu, TYPE_VIA_PMU);
-        object_property_set_link(OBJECT(&s->pmu), "gpio", OBJECT(sysbus_dev),
-                                 &error_abort);
+        qdev_prop_set_link(DEVICE(&s->pmu), "gpio", OBJECT(sysbus_dev));
         qdev_prop_set_bit(DEVICE(&s->pmu), "has-adb", ns->has_adb);
         if (!qdev_realize(DEVICE(&s->pmu), BUS(&s->macio_bus), errp)) {
             return;
Signature · 1 line
2.38.1
#2 lore raw

PATCH 2/5 hw/pci-host/raven: Set QDev properties using QDev API

In reply to 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.

All calls use either errp=&error_fatal or NULL, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

---
 hw/pci-host/raven.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/pci-host/raven.c +2 -4
index cdfb62ac2e..2c842d2146 100644
@@ -246,8 +246,7 @@ static void raven_pcihost_realizefn(DeviceState *d, Error **errp)
         /* According to PReP specification section 6.1.6 "System Interrupt
          * Assignments", all PCI interrupts are routed via IRQ 15 */
         s->or_irq = OR_IRQ(object_new(TYPE_OR_IRQ));
-        object_property_set_int(OBJECT(s->or_irq), "num-lines", PCI_NUM_PINS,
-                                &error_fatal);
+        qdev_prop_set_uint16(DEVICE(s->or_irq), "num-lines", PCI_NUM_PINS);
         qdev_realize(DEVICE(s->or_irq), NULL, &error_fatal);
         sysbus_init_irq(dev, &s->or_irq->out_irq);
 
@@ -319,8 +318,7 @@ static void raven_pcihost_initfn(Object *obj)
 
     object_initialize(&s->pci_dev, sizeof(s->pci_dev), TYPE_RAVEN_PCI_DEVICE);
     pci_dev = DEVICE(&s->pci_dev);
-    object_property_set_int(OBJECT(&s->pci_dev), "addr", PCI_DEVFN(0, 0),
-                            NULL);
+    qdev_prop_set_int32(pci_dev, "addr", PCI_DEVFN(0, 0));
     qdev_prop_set_bit(pci_dev, "multifunction", false);
 }
 
Signature · 1 line
2.38.1
Reviewed-by on v1 2/5
#3 lore raw

Re: [PATCH 2/5] hw/pci-host/raven: Set QDev properties using QDev API

Quoted 10 lines · 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.

All calls use either errp=&error_fatal or NULL, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

---

Quoted 27 lines
  hw/pci-host/raven.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
hw/pci-host/raven.c +2 -4
index cdfb62ac2e..2c842d2146 100644
@@ -246,8 +246,7 @@ static void raven_pcihost_realizefn(DeviceState *d, Error **errp)
          /* According to PReP specification section 6.1.6 "System Interrupt
           * Assignments", all PCI interrupts are routed via IRQ 15 */
          s->or_irq = OR_IRQ(object_new(TYPE_OR_IRQ));
-        object_property_set_int(OBJECT(s->or_irq), "num-lines", PCI_NUM_PINS,
-                                &error_fatal);
+        qdev_prop_set_uint16(DEVICE(s->or_irq), "num-lines", PCI_NUM_PINS);
          qdev_realize(DEVICE(s->or_irq), NULL, &error_fatal);
          sysbus_init_irq(dev, &s->or_irq->out_irq);
 
@@ -319,8 +318,7 @@ static void raven_pcihost_initfn(Object *obj)
 
      object_initialize(&s->pci_dev, sizeof(s->pci_dev), TYPE_RAVEN_PCI_DEVICE);
      pci_dev = DEVICE(&s->pci_dev);
-    object_property_set_int(OBJECT(&s->pci_dev), "addr", PCI_DEVFN(0, 0),
-                            NULL);
+    qdev_prop_set_int32(pci_dev, "addr", PCI_DEVFN(0, 0));
      qdev_prop_set_bit(pci_dev, "multifunction", false);
  }
 
#4 lore raw

PATCH 3/5 hw/ppc/ppc4xx: Set QDev properties using QDev API

In reply to 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.

All calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

---
 hw/ppc/e500.c          | 3 +--
 hw/ppc/ppc405_boards.c | 6 ++----
 hw/ppc/ppc405_uc.c     | 6 +++---
 hw/ppc/ppc440_bamboo.c | 3 +--
 hw/ppc/ppc4xx_devs.c   | 2 +-
 hw/ppc/sam460ex.c      | 5 ++---
 6 files changed, 10 insertions(+), 15 deletions(-)
hw/ppc/e500.c +1 -2
index 9fa1f8e6cf..083961cef5 100644
@@ -943,8 +943,7 @@ void ppce500_init(MachineState *machine)
          * Secondary CPU starts in halted state for now. Needs to change
          * when implementing non-kernel boot.
          */
-        object_property_set_bool(OBJECT(cs), "start-powered-off", i != 0,
-                                 &error_fatal);
+        qdev_prop_set_bit(DEVICE(cs), "start-powered-off", i != 0);
         qdev_realize_and_unref(DEVICE(cs), NULL, &error_fatal);
 
         if (!firstenv) {
hw/ppc/ppc405_boards.c +2 -4
index 4092ebc1ab..67eb9ac139 100644
@@ -276,10 +276,8 @@ static void ppc405_init(MachineState *machine)
 
     object_initialize_child(OBJECT(machine), "soc", &ppc405->soc,
                             TYPE_PPC405_SOC);
-    object_property_set_link(OBJECT(&ppc405->soc), "dram",
-                             OBJECT(machine->ram), &error_abort);
-    object_property_set_uint(OBJECT(&ppc405->soc), "sys-clk", 33333333,
-                             &error_abort);
+    qdev_prop_set_link(DEVICE(&ppc405->soc), "dram", OBJECT(machine->ram));
+    qdev_prop_set_uint32(DEVICE(&ppc405->soc), "sys-clk", 33333333);
     qdev_realize(DEVICE(&ppc405->soc), NULL, &error_fatal);
 
     /* allocate and load BIOS */
hw/ppc/ppc405_uc.c +3 -3
index c973cfb04e..b7d5cfc548 100644
@@ -1080,7 +1080,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)
      * We use the 440 DDR SDRAM controller which has more regs and features
      * but it's compatible enough for now
      */
-    object_property_set_int(OBJECT(&s->sdram), "nbanks", 2, &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->sdram), "nbanks", 2);
     if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->sdram), &s->cpu, errp)) {
         return;
     }
@@ -1147,8 +1147,8 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)
     }
 
     /* MAL */
-    object_property_set_int(OBJECT(&s->mal), "txc-num", 4, &error_abort);
-    object_property_set_int(OBJECT(&s->mal), "rxc-num", 2, &error_abort);
+    qdev_prop_set_uint8(DEVICE(&s->mal), "txc-num", 4);
+    qdev_prop_set_uint8(DEVICE(&s->mal), "rxc-num", 2);
     if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->mal), &s->cpu, errp)) {
         return;
     }
hw/ppc/ppc440_bamboo.c +1 -2
index 81d71adf34..3612471990 100644
@@ -200,8 +200,7 @@ static void bamboo_init(MachineState *machine)
 
     /* SDRAM controller */
     dev = qdev_new(TYPE_PPC4xx_SDRAM_DDR);
-    object_property_set_link(OBJECT(dev), "dram", OBJECT(machine->ram),
-                             &error_abort);
+    qdev_prop_set_link(dev, "dram", OBJECT(machine->ram));
     ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(dev), cpu, &error_fatal);
     object_unref(OBJECT(dev));
     /* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */
hw/ppc/ppc4xx_devs.c +1 -1
index c1d111465d..1848cf5d3c 100644
@@ -535,7 +535,7 @@ void ppc4xx_dcr_register(Ppc4xxDcrDeviceState *dev, int dcrn, void *opaque,
 bool ppc4xx_dcr_realize(Ppc4xxDcrDeviceState *dev, PowerPCCPU *cpu,
                         Error **errp)
 {
-    object_property_set_link(OBJECT(dev), "cpu", OBJECT(cpu), &error_abort);
+    qdev_prop_set_link(DEVICE(dev), "cpu", OBJECT(cpu));
     return sysbus_realize(SYS_BUS_DEVICE(dev), errp);
 }
 
hw/ppc/sam460ex.c +2 -3
index cf065aae0e..cb828b6d4d 100644
@@ -345,13 +345,12 @@ static void sam460ex_init(MachineState *machine)
         exit(1);
     }
     dev = qdev_new(TYPE_PPC4xx_SDRAM_DDR2);
-    object_property_set_link(OBJECT(dev), "dram", OBJECT(machine->ram),
-                             &error_abort);
+    qdev_prop_set_link(dev, "dram", OBJECT(machine->ram));
     /*
      * Put all RAM on first bank because board has one slot
      * and firmware only checks that
      */
-    object_property_set_int(OBJECT(dev), "nbanks", 1, &error_abort);
+    qdev_prop_set_uint32(dev, "nbanks", 1);
     ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(dev), cpu, &error_fatal);
     object_unref(OBJECT(dev));
     /* FIXME: does 460EX have ECC interrupts? */
Signature · 1 line
2.38.1
Reviewed-by on v1 3/5
#5 lore raw

Re: [PATCH 3/5] hw/ppc/ppc4xx: Set QDev properties using QDev API

Quoted 9 lines · 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.

All calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

Quoted 112 lines

---

hw/ppc/e500.c          | 3 +--
hw/ppc/ppc405_boards.c | 6 ++----
hw/ppc/ppc405_uc.c     | 6 +++---
hw/ppc/ppc440_bamboo.c | 3 +--
hw/ppc/ppc4xx_devs.c   | 2 +-
hw/ppc/sam460ex.c      | 5 ++---
6 files changed, 10 insertions(+), 15 deletions(-)
hw/ppc/e500.c +1 -2
index 9fa1f8e6cf..083961cef5 100644
@@ -943,8 +943,7 @@ void ppce500_init(MachineState *machine)
         * Secondary CPU starts in halted state for now. Needs to change
         * when implementing non-kernel boot.
         */
-        object_property_set_bool(OBJECT(cs), "start-powered-off", i != 0,
-                                 &error_fatal);
+        qdev_prop_set_bit(DEVICE(cs), "start-powered-off", i != 0);
        qdev_realize_and_unref(DEVICE(cs), NULL, &error_fatal);
 
        if (!firstenv) {
hw/ppc/ppc405_boards.c +2 -4
index 4092ebc1ab..67eb9ac139 100644
@@ -276,10 +276,8 @@ static void ppc405_init(MachineState *machine)
 
    object_initialize_child(OBJECT(machine), "soc", &ppc405->soc,
                            TYPE_PPC405_SOC);
-    object_property_set_link(OBJECT(&ppc405->soc), "dram",
-                             OBJECT(machine->ram), &error_abort);
-    object_property_set_uint(OBJECT(&ppc405->soc), "sys-clk", 33333333,
-                             &error_abort);
+    qdev_prop_set_link(DEVICE(&ppc405->soc), "dram", OBJECT(machine->ram));
+    qdev_prop_set_uint32(DEVICE(&ppc405->soc), "sys-clk", 33333333);
    qdev_realize(DEVICE(&ppc405->soc), NULL, &error_fatal);
 
    /* allocate and load BIOS */
hw/ppc/ppc405_uc.c +3 -3
index c973cfb04e..b7d5cfc548 100644
@@ -1080,7 +1080,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)
     * We use the 440 DDR SDRAM controller which has more regs and features
     * but it's compatible enough for now
     */
-    object_property_set_int(OBJECT(&s->sdram), "nbanks", 2, &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->sdram), "nbanks", 2);
    if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->sdram), &s->cpu, errp)) {
        return;
    }
@@ -1147,8 +1147,8 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)
    }
 
    /* MAL */
-    object_property_set_int(OBJECT(&s->mal), "txc-num", 4, &error_abort);
-    object_property_set_int(OBJECT(&s->mal), "rxc-num", 2, &error_abort);
+    qdev_prop_set_uint8(DEVICE(&s->mal), "txc-num", 4);
+    qdev_prop_set_uint8(DEVICE(&s->mal), "rxc-num", 2);
    if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->mal), &s->cpu, errp)) {
        return;
    }
hw/ppc/ppc440_bamboo.c +1 -2
index 81d71adf34..3612471990 100644
@@ -200,8 +200,7 @@ static void bamboo_init(MachineState *machine)
 
    /* SDRAM controller */
    dev = qdev_new(TYPE_PPC4xx_SDRAM_DDR);
-    object_property_set_link(OBJECT(dev), "dram", OBJECT(machine->ram),
-                             &error_abort);
+    qdev_prop_set_link(dev, "dram", OBJECT(machine->ram));
    ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(dev), cpu, &error_fatal);
    object_unref(OBJECT(dev));
    /* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */
hw/ppc/ppc4xx_devs.c +1 -1
index c1d111465d..1848cf5d3c 100644
@@ -535,7 +535,7 @@ void ppc4xx_dcr_register(Ppc4xxDcrDeviceState *dev, int dcrn, void *opaque,
 bool ppc4xx_dcr_realize(Ppc4xxDcrDeviceState *dev, PowerPCCPU *cpu,
                        Error **errp)
 {
-    object_property_set_link(OBJECT(dev), "cpu", OBJECT(cpu), &error_abort);
+    qdev_prop_set_link(DEVICE(dev), "cpu", OBJECT(cpu));
    return sysbus_realize(SYS_BUS_DEVICE(dev), errp);
 }
 
hw/ppc/sam460ex.c +2 -3
index cf065aae0e..cb828b6d4d 100644
@@ -345,13 +345,12 @@ static void sam460ex_init(MachineState *machine)
        exit(1);
    }
    dev = qdev_new(TYPE_PPC4xx_SDRAM_DDR2);
-    object_property_set_link(OBJECT(dev), "dram", OBJECT(machine->ram),
-                             &error_abort);
+    qdev_prop_set_link(dev, "dram", OBJECT(machine->ram));
    /*
     * Put all RAM on first bank because board has one slot
     * and firmware only checks that
     */
-    object_property_set_int(OBJECT(dev), "nbanks", 1, &error_abort);
+    qdev_prop_set_uint32(dev, "nbanks", 1);
    ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(dev), cpu, &error_fatal);
    object_unref(OBJECT(dev));
    /* FIXME: does 460EX have ECC interrupts? */
Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH 3/5] hw/ppc/ppc4xx: Set QDev properties using QDev API

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · 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.

All calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

---

Quoted 110 lines
  hw/ppc/e500.c          | 3 +--
  hw/ppc/ppc405_boards.c | 6 ++----
  hw/ppc/ppc405_uc.c     | 6 +++---
  hw/ppc/ppc440_bamboo.c | 3 +--
  hw/ppc/ppc4xx_devs.c   | 2 +-
  hw/ppc/sam460ex.c      | 5 ++---
  6 files changed, 10 insertions(+), 15 deletions(-)
hw/ppc/e500.c +1 -2
index 9fa1f8e6cf..083961cef5 100644
@@ -943,8 +943,7 @@ void ppce500_init(MachineState *machine)
           * Secondary CPU starts in halted state for now. Needs to change
           * when implementing non-kernel boot.
           */
-        object_property_set_bool(OBJECT(cs), "start-powered-off", i != 0,
-                                 &error_fatal);
+        qdev_prop_set_bit(DEVICE(cs), "start-powered-off", i != 0);
          qdev_realize_and_unref(DEVICE(cs), NULL, &error_fatal);
 
          if (!firstenv) {
hw/ppc/ppc405_boards.c +2 -4
index 4092ebc1ab..67eb9ac139 100644
@@ -276,10 +276,8 @@ static void ppc405_init(MachineState *machine)
 
      object_initialize_child(OBJECT(machine), "soc", &ppc405->soc,
                              TYPE_PPC405_SOC);
-    object_property_set_link(OBJECT(&ppc405->soc), "dram",
-                             OBJECT(machine->ram), &error_abort);
-    object_property_set_uint(OBJECT(&ppc405->soc), "sys-clk", 33333333,
-                             &error_abort);
+    qdev_prop_set_link(DEVICE(&ppc405->soc), "dram", OBJECT(machine->ram));
+    qdev_prop_set_uint32(DEVICE(&ppc405->soc), "sys-clk", 33333333);
      qdev_realize(DEVICE(&ppc405->soc), NULL, &error_fatal);
 
      /* allocate and load BIOS */
hw/ppc/ppc405_uc.c +3 -3
index c973cfb04e..b7d5cfc548 100644
@@ -1080,7 +1080,7 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)
       * We use the 440 DDR SDRAM controller which has more regs and features
       * but it's compatible enough for now
       */
-    object_property_set_int(OBJECT(&s->sdram), "nbanks", 2, &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->sdram), "nbanks", 2);
      if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->sdram), &s->cpu, errp)) {
          return;
      }
@@ -1147,8 +1147,8 @@ static void ppc405_soc_realize(DeviceState *dev, Error **errp)
      }
 
      /* MAL */
-    object_property_set_int(OBJECT(&s->mal), "txc-num", 4, &error_abort);
-    object_property_set_int(OBJECT(&s->mal), "rxc-num", 2, &error_abort);
+    qdev_prop_set_uint8(DEVICE(&s->mal), "txc-num", 4);
+    qdev_prop_set_uint8(DEVICE(&s->mal), "rxc-num", 2);
      if (!ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(&s->mal), &s->cpu, errp)) {
          return;
      }
hw/ppc/ppc440_bamboo.c +1 -2
index 81d71adf34..3612471990 100644
@@ -200,8 +200,7 @@ static void bamboo_init(MachineState *machine)
 
      /* SDRAM controller */
      dev = qdev_new(TYPE_PPC4xx_SDRAM_DDR);
-    object_property_set_link(OBJECT(dev), "dram", OBJECT(machine->ram),
-                             &error_abort);
+    qdev_prop_set_link(dev, "dram", OBJECT(machine->ram));
      ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(dev), cpu, &error_fatal);
      object_unref(OBJECT(dev));
      /* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */
hw/ppc/ppc4xx_devs.c +1 -1
index c1d111465d..1848cf5d3c 100644
@@ -535,7 +535,7 @@ void ppc4xx_dcr_register(Ppc4xxDcrDeviceState *dev, int dcrn, void *opaque,
  bool ppc4xx_dcr_realize(Ppc4xxDcrDeviceState *dev, PowerPCCPU *cpu,
                          Error **errp)
  {
-    object_property_set_link(OBJECT(dev), "cpu", OBJECT(cpu), &error_abort);
+    qdev_prop_set_link(DEVICE(dev), "cpu", OBJECT(cpu));
      return sysbus_realize(SYS_BUS_DEVICE(dev), errp);
  }
 
hw/ppc/sam460ex.c +2 -3
index cf065aae0e..cb828b6d4d 100644
@@ -345,13 +345,12 @@ static void sam460ex_init(MachineState *machine)
          exit(1);
      }
      dev = qdev_new(TYPE_PPC4xx_SDRAM_DDR2);
-    object_property_set_link(OBJECT(dev), "dram", OBJECT(machine->ram),
-                             &error_abort);
+    qdev_prop_set_link(dev, "dram", OBJECT(machine->ram));
      /*
       * Put all RAM on first bank because board has one slot
       * and firmware only checks that
       */
-    object_property_set_int(OBJECT(dev), "nbanks", 1, &error_abort);
+    qdev_prop_set_uint32(dev, "nbanks", 1);
      ppc4xx_dcr_realize(PPC4xx_DCR_DEVICE(dev), cpu, &error_fatal);
      object_unref(OBJECT(dev));
      /* FIXME: does 460EX have ECC interrupts? */
#7 lore raw

PATCH 4/5 hw/ppc/spapr: Set QDev properties using QDev API

In reply to 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.

All calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

---
 hw/intc/spapr_xive.c | 11 ++++-------
 hw/intc/xics.c       |  4 ++--
 hw/intc/xive.c       |  4 ++--
 hw/ppc/spapr_irq.c   |  8 +++-----
 4 files changed, 11 insertions(+), 16 deletions(-)
hw/intc/spapr_xive.c +4 -7
index dc641cc604..213c4cac44 100644
@@ -310,9 +310,8 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)
     /*
      * Initialize the internal sources, for IPIs and virtual devices.
      */
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", xive->nr_irqs,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", xive->nr_irqs);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
     if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
         return;
     }
@@ -321,10 +320,8 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)
     /*
      * Initialize the END ESB source
      */
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", xive->nr_irqs,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", xive->nr_irqs);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
     if (!qdev_realize(DEVICE(end_xsrc), NULL, errp)) {
         return;
     }
hw/intc/xics.c +2 -2
index c7f8abd71e..2fd1a15153 100644
@@ -382,8 +382,8 @@ Object *icp_create(Object *cpu, const char *type, XICSFabric *xi, Error **errp)
     obj = object_new(type);
     object_property_add_child(cpu, type, obj);
     object_unref(obj);
-    object_property_set_link(obj, ICP_PROP_XICS, OBJECT(xi), &error_abort);
-    object_property_set_link(obj, ICP_PROP_CPU, cpu, &error_abort);
+    qdev_prop_set_link(DEVICE(obj), ICP_PROP_XICS, OBJECT(xi));
+    qdev_prop_set_link(DEVICE(obj), ICP_PROP_CPU, cpu);
     if (!qdev_realize(DEVICE(obj), NULL, errp)) {
         object_unparent(obj);
         obj = NULL;
hw/intc/xive.c +2 -2
index a986b96843..0e34035bc6 100644
@@ -799,8 +799,8 @@ Object *xive_tctx_create(Object *cpu, XivePresenter *xptr, Error **errp)
     obj = object_new(TYPE_XIVE_TCTX);
     object_property_add_child(cpu, TYPE_XIVE_TCTX, obj);
     object_unref(obj);
-    object_property_set_link(obj, "cpu", cpu, &error_abort);
-    object_property_set_link(obj, "presenter", OBJECT(xptr), &error_abort);
+    qdev_prop_set_link(DEVICE(obj), "cpu", cpu);
+    qdev_prop_set_link(DEVICE(obj), "presenter", OBJECT(xptr));
     if (!qdev_realize(DEVICE(obj), NULL, errp)) {
         object_unparent(obj);
         return NULL;
hw/ppc/spapr_irq.c +3 -5
index a0d1e1298e..283769c074 100644
@@ -313,9 +313,8 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
         obj = object_new(TYPE_ICS_SPAPR);
 
         object_property_add_child(OBJECT(spapr), "ics", obj);
-        object_property_set_link(obj, ICS_PROP_XICS, OBJECT(spapr),
-                                 &error_abort);
-        object_property_set_int(obj, "nr-irqs", smc->nr_xirqs, &error_abort);
+        qdev_prop_set_link(DEVICE(obj), ICS_PROP_XICS, OBJECT(spapr));
+        qdev_prop_set_uint32(DEVICE(obj), "nr-irqs", smc->nr_xirqs);
         if (!qdev_realize(DEVICE(obj), NULL, errp)) {
             return;
         }
@@ -335,8 +334,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
          * priority
          */
         qdev_prop_set_uint32(dev, "nr-ends", nr_servers << 3);
-        object_property_set_link(OBJECT(dev), "xive-fabric", OBJECT(spapr),
-                                 &error_abort);
+        qdev_prop_set_link(dev, "xive-fabric", OBJECT(spapr));
         sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
         spapr->xive = SPAPR_XIVE(dev);
Signature · 1 line
2.38.1
Reviewed-by on v1 4/5
#8 lore raw

Re: [PATCH 4/5] hw/ppc/spapr: Set QDev properties using QDev API

Quoted 10 lines · 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.

All calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

---

Quoted 91 lines
  hw/intc/spapr_xive.c | 11 ++++-------
  hw/intc/xics.c       |  4 ++--
  hw/intc/xive.c       |  4 ++--
  hw/ppc/spapr_irq.c   |  8 +++-----
  4 files changed, 11 insertions(+), 16 deletions(-)
hw/intc/spapr_xive.c +4 -7
index dc641cc604..213c4cac44 100644
@@ -310,9 +310,8 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)
      /*
       * Initialize the internal sources, for IPIs and virtual devices.
       */
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", xive->nr_irqs,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", xive->nr_irqs);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
      if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
          return;
      }
@@ -321,10 +320,8 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)
      /*
       * Initialize the END ESB source
       */
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", xive->nr_irqs,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", xive->nr_irqs);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
      if (!qdev_realize(DEVICE(end_xsrc), NULL, errp)) {
          return;
      }
hw/intc/xics.c +2 -2
index c7f8abd71e..2fd1a15153 100644
@@ -382,8 +382,8 @@ Object *icp_create(Object *cpu, const char *type, XICSFabric *xi, Error **errp)
      obj = object_new(type);
      object_property_add_child(cpu, type, obj);
      object_unref(obj);
-    object_property_set_link(obj, ICP_PROP_XICS, OBJECT(xi), &error_abort);
-    object_property_set_link(obj, ICP_PROP_CPU, cpu, &error_abort);
+    qdev_prop_set_link(DEVICE(obj), ICP_PROP_XICS, OBJECT(xi));
+    qdev_prop_set_link(DEVICE(obj), ICP_PROP_CPU, cpu);
      if (!qdev_realize(DEVICE(obj), NULL, errp)) {
          object_unparent(obj);
          obj = NULL;
hw/intc/xive.c +2 -2
index a986b96843..0e34035bc6 100644
@@ -799,8 +799,8 @@ Object *xive_tctx_create(Object *cpu, XivePresenter *xptr, Error **errp)
      obj = object_new(TYPE_XIVE_TCTX);
      object_property_add_child(cpu, TYPE_XIVE_TCTX, obj);
      object_unref(obj);
-    object_property_set_link(obj, "cpu", cpu, &error_abort);
-    object_property_set_link(obj, "presenter", OBJECT(xptr), &error_abort);
+    qdev_prop_set_link(DEVICE(obj), "cpu", cpu);
+    qdev_prop_set_link(DEVICE(obj), "presenter", OBJECT(xptr));
      if (!qdev_realize(DEVICE(obj), NULL, errp)) {
          object_unparent(obj);
          return NULL;
hw/ppc/spapr_irq.c +3 -5
index a0d1e1298e..283769c074 100644
@@ -313,9 +313,8 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
          obj = object_new(TYPE_ICS_SPAPR);
 
          object_property_add_child(OBJECT(spapr), "ics", obj);
-        object_property_set_link(obj, ICS_PROP_XICS, OBJECT(spapr),
-                                 &error_abort);
-        object_property_set_int(obj, "nr-irqs", smc->nr_xirqs, &error_abort);
+        qdev_prop_set_link(DEVICE(obj), ICS_PROP_XICS, OBJECT(spapr));
+        qdev_prop_set_uint32(DEVICE(obj), "nr-irqs", smc->nr_xirqs);
          if (!qdev_realize(DEVICE(obj), NULL, errp)) {
              return;
          }
@@ -335,8 +334,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
           * priority
           */
          qdev_prop_set_uint32(dev, "nr-ends", nr_servers << 3);
-        object_property_set_link(OBJECT(dev), "xive-fabric", OBJECT(spapr),
-                                 &error_abort);
+        qdev_prop_set_link(dev, "xive-fabric", OBJECT(spapr));
          sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
          spapr->xive = SPAPR_XIVE(dev);
Reviewed-by on v1 4/5
#9 lore raw

Re: [PATCH 4/5] hw/ppc/spapr: Set QDev properties using QDev API

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · 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.

All calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

Thanks,

C.

Quoted 92 lines
---
  hw/intc/spapr_xive.c | 11 ++++-------
  hw/intc/xics.c       |  4 ++--
  hw/intc/xive.c       |  4 ++--
  hw/ppc/spapr_irq.c   |  8 +++-----
  4 files changed, 11 insertions(+), 16 deletions(-)
hw/intc/spapr_xive.c +4 -7
index dc641cc604..213c4cac44 100644
@@ -310,9 +310,8 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)
      /*
       * Initialize the internal sources, for IPIs and virtual devices.
       */
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", xive->nr_irqs,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", xive->nr_irqs);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
      if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
          return;
      }
@@ -321,10 +320,8 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)
      /*
       * Initialize the END ESB source
       */
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", xive->nr_irqs,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", xive->nr_irqs);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
      if (!qdev_realize(DEVICE(end_xsrc), NULL, errp)) {
          return;
      }
hw/intc/xics.c +2 -2
index c7f8abd71e..2fd1a15153 100644
@@ -382,8 +382,8 @@ Object *icp_create(Object *cpu, const char *type, XICSFabric *xi, Error **errp)
      obj = object_new(type);
      object_property_add_child(cpu, type, obj);
      object_unref(obj);
-    object_property_set_link(obj, ICP_PROP_XICS, OBJECT(xi), &error_abort);
-    object_property_set_link(obj, ICP_PROP_CPU, cpu, &error_abort);
+    qdev_prop_set_link(DEVICE(obj), ICP_PROP_XICS, OBJECT(xi));
+    qdev_prop_set_link(DEVICE(obj), ICP_PROP_CPU, cpu);
      if (!qdev_realize(DEVICE(obj), NULL, errp)) {
          object_unparent(obj);
          obj = NULL;
hw/intc/xive.c +2 -2
index a986b96843..0e34035bc6 100644
@@ -799,8 +799,8 @@ Object *xive_tctx_create(Object *cpu, XivePresenter *xptr, Error **errp)
      obj = object_new(TYPE_XIVE_TCTX);
      object_property_add_child(cpu, TYPE_XIVE_TCTX, obj);
      object_unref(obj);
-    object_property_set_link(obj, "cpu", cpu, &error_abort);
-    object_property_set_link(obj, "presenter", OBJECT(xptr), &error_abort);
+    qdev_prop_set_link(DEVICE(obj), "cpu", cpu);
+    qdev_prop_set_link(DEVICE(obj), "presenter", OBJECT(xptr));
      if (!qdev_realize(DEVICE(obj), NULL, errp)) {
          object_unparent(obj);
          return NULL;
hw/ppc/spapr_irq.c +3 -5
index a0d1e1298e..283769c074 100644
@@ -313,9 +313,8 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
          obj = object_new(TYPE_ICS_SPAPR);
 
          object_property_add_child(OBJECT(spapr), "ics", obj);
-        object_property_set_link(obj, ICS_PROP_XICS, OBJECT(spapr),
-                                 &error_abort);
-        object_property_set_int(obj, "nr-irqs", smc->nr_xirqs, &error_abort);
+        qdev_prop_set_link(DEVICE(obj), ICS_PROP_XICS, OBJECT(spapr));
+        qdev_prop_set_uint32(DEVICE(obj), "nr-irqs", smc->nr_xirqs);
          if (!qdev_realize(DEVICE(obj), NULL, errp)) {
              return;
          }
@@ -335,8 +334,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
           * priority
           */
          qdev_prop_set_uint32(dev, "nr-ends", nr_servers << 3);
-        object_property_set_link(OBJECT(dev), "xive-fabric", OBJECT(spapr),
-                                 &error_abort);
+        qdev_prop_set_link(dev, "xive-fabric", OBJECT(spapr));
          sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
          spapr->xive = SPAPR_XIVE(dev);
#10 lore raw

PATCH 5/5 hw/ppc/pnv: Set QDev properties using QDev API

In reply to 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.

One call in pnv_psi_power8_realize() propagate the Error* argument:

  if (!object_property_set_int(OBJECT(ics), "nr-irqs",
                               PSI_NUM_INTERRUPTS, errp)) {
      return;
  }

TYPE_ICS "nr-irqs" is declared in ics_properties[], itself always registered in ics_class_init(); so converting this errp to &error_abort is safe.

All other calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

---
 hw/intc/pnv_xive.c         | 11 ++++------
 hw/intc/pnv_xive2.c        | 15 +++++---------
 hw/pci-host/pnv_phb3.c     |  9 +++------
 hw/pci-host/pnv_phb4.c     |  4 ++--
 hw/pci-host/pnv_phb4_pec.c | 10 +++-------
 hw/ppc/pnv.c               | 41 ++++++++++++++++----------------------
 hw/ppc/pnv_psi.c           | 10 +++-------
 7 files changed, 37 insertions(+), 63 deletions(-)
hw/intc/pnv_xive.c +4 -7
index 622f9d28b7..ccc1ea5380 100644
@@ -1857,17 +1857,14 @@ static void pnv_xive_realize(DeviceState *dev, Error **errp)
      * resized dynamically when the controller is configured by the FW
      * to limit accesses to resources not provisioned.
      */
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PNV_XIVE_NR_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PNV_XIVE_NR_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
     if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
         return;
     }
 
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", PNV_XIVE_NR_ENDS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", PNV_XIVE_NR_ENDS);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
     if (!qdev_realize(DEVICE(end_xsrc), NULL, errp)) {
         return;
     }
hw/intc/pnv_xive2.c +5 -10
index 7176d70234..d7695f65e7 100644
@@ -1821,22 +1821,17 @@ static void pnv_xive2_realize(DeviceState *dev, Error **errp)
      * resized dynamically when the controller is configured by the FW
      * to limit accesses to resources not provisioned.
      */
-    object_property_set_int(OBJECT(xsrc), "flags", XIVE_SRC_STORE_EOI,
-                            &error_fatal);
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PNV_XIVE2_NR_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive),
-                             &error_fatal);
+    qdev_prop_set_uint64(DEVICE(xsrc), "flags", XIVE_SRC_STORE_EOI);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PNV_XIVE2_NR_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
     qdev_realize(DEVICE(xsrc), NULL, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return;
     }
 
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", PNV_XIVE2_NR_ENDS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", PNV_XIVE2_NR_ENDS);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
     qdev_realize(DEVICE(end_xsrc), NULL, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
hw/pci-host/pnv_phb3.c +3 -6
index 7a21497cf8..6da9053ffa 100644
@@ -1029,8 +1029,7 @@ static void pnv_phb3_realize(DeviceState *dev, Error **errp)
     /* LSI sources */
     object_property_set_link(OBJECT(&phb->lsis), "xics", OBJECT(pnv),
                              &error_abort);
-    object_property_set_int(OBJECT(&phb->lsis), "nr-irqs", PNV_PHB3_NUM_LSI,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&phb->lsis), "nr-irqs", PNV_PHB3_NUM_LSI);
     if (!qdev_realize(DEVICE(&phb->lsis), NULL, errp)) {
         return;
     }
@@ -1046,15 +1045,13 @@ static void pnv_phb3_realize(DeviceState *dev, Error **errp)
                              &error_abort);
     object_property_set_link(OBJECT(&phb->msis), "xics", OBJECT(pnv),
                              &error_abort);
-    object_property_set_int(OBJECT(&phb->msis), "nr-irqs", PHB3_MAX_MSI,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&phb->msis), "nr-irqs", PHB3_MAX_MSI);
     if (!qdev_realize(DEVICE(&phb->msis), NULL, errp)) {
         return;
     }
 
     /* Power Bus Common Queue */
-    object_property_set_link(OBJECT(&phb->pbcq), "phb", OBJECT(phb),
-                             &error_abort);
+    qdev_prop_set_link(DEVICE(&phb->pbcq), "phb", OBJECT(phb));
     if (!qdev_realize(DEVICE(&phb->pbcq), NULL, errp)) {
         return;
     }
hw/pci-host/pnv_phb4.c +2 -2
index ccbde841fc..c4e7cb0efe 100644
@@ -1583,8 +1583,8 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
     } else {
         nr_irqs = PNV_PHB4_MAX_INTs >> 1;
     }
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", nr_irqs, &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(phb), &error_fatal);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", nr_irqs);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(phb));
     if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
         return;
     }
hw/pci-host/pnv_phb4_pec.c +3 -7
index 43267a428f..9c21382330 100644
@@ -120,13 +120,9 @@ static void pnv_pec_default_phb_realize(PnvPhb4PecState *pec,
     int phb_id = pnv_phb4_pec_get_phb_id(pec, stack_no);
 
     object_property_add_child(OBJECT(pec), "phb[*]", OBJECT(phb));
-    object_property_set_link(OBJECT(phb), "pec", OBJECT(pec),
-                             &error_abort);
-    object_property_set_int(OBJECT(phb), "chip-id", pec->chip_id,
-                            &error_fatal);
-    object_property_set_int(OBJECT(phb), "index", phb_id,
-                            &error_fatal);
-
+    qdev_prop_set_link(DEVICE(phb), "pec", OBJECT(pec));
+    qdev_prop_set_uint32(DEVICE(phb), "chip-id", pec->chip_id);
+    qdev_prop_set_uint32(DEVICE(phb), "index", phb_id);
     if (!sysbus_realize(SYS_BUS_DEVICE(phb), errp)) {
         return;
     }
hw/ppc/pnv.c +17 -24

75 lines not on this page · raw message

hw/ppc/pnv_psi.c +3 -7
index 8aa09ab26b..fb90d47138 100644
@@ -492,10 +492,7 @@ static void pnv_psi_power8_realize(DeviceState *dev, Error **errp)
     unsigned int i;
 
     /* Create PSI interrupt control source */
-    if (!object_property_set_int(OBJECT(ics), "nr-irqs", PSI_NUM_INTERRUPTS,
-                                 errp)) {
-        return;
-    }
+    qdev_prop_set_uint32(DEVICE(ics), "nr-irqs", PSI_NUM_INTERRUPTS);
     if (!qdev_realize(DEVICE(ics), NULL, errp)) {
         return;
     }
@@ -849,9 +846,8 @@ static void pnv_psi_power9_realize(DeviceState *dev, Error **errp)
     XiveSource *xsrc = &PNV9_PSI(psi)->source;
     int i;
 
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PSIHB9_NUM_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(psi), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PSIHB9_NUM_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(psi));
     if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
         return;
     }
Signature · 1 line
2.38.1
Reviewed-by on v1 5/5
#11 lore raw

Re: [PATCH 5/5] hw/ppc/pnv: Set QDev properties using QDev API

Quoted 16 lines · 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.

One call in pnv_psi_power8_realize() propagate the Error* argument:

   if (!object_property_set_int(OBJECT(ics), "nr-irqs",
                                PSI_NUM_INTERRUPTS, errp)) {
       return;
   }

TYPE_ICS "nr-irqs" is declared in ics_properties[], itself always registered in ics_class_init(); so converting this errp to &error_abort is safe.

Quoted 6 lines

All other calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

---

Quoted 245 lines
  hw/intc/pnv_xive.c         | 11 ++++------
  hw/intc/pnv_xive2.c        | 15 +++++---------
  hw/pci-host/pnv_phb3.c     |  9 +++------
  hw/pci-host/pnv_phb4.c     |  4 ++--
  hw/pci-host/pnv_phb4_pec.c | 10 +++-------
  hw/ppc/pnv.c               | 41 ++++++++++++++++----------------------
  hw/ppc/pnv_psi.c           | 10 +++-------
  7 files changed, 37 insertions(+), 63 deletions(-)
hw/intc/pnv_xive.c +4 -7
index 622f9d28b7..ccc1ea5380 100644
@@ -1857,17 +1857,14 @@ static void pnv_xive_realize(DeviceState *dev, Error **errp)
       * resized dynamically when the controller is configured by the FW
       * to limit accesses to resources not provisioned.
       */
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PNV_XIVE_NR_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PNV_XIVE_NR_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
      if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
          return;
      }
 
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", PNV_XIVE_NR_ENDS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", PNV_XIVE_NR_ENDS);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
      if (!qdev_realize(DEVICE(end_xsrc), NULL, errp)) {
          return;
      }
hw/intc/pnv_xive2.c +5 -10
index 7176d70234..d7695f65e7 100644
@@ -1821,22 +1821,17 @@ static void pnv_xive2_realize(DeviceState *dev, Error **errp)
       * resized dynamically when the controller is configured by the FW
       * to limit accesses to resources not provisioned.
       */
-    object_property_set_int(OBJECT(xsrc), "flags", XIVE_SRC_STORE_EOI,
-                            &error_fatal);
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PNV_XIVE2_NR_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive),
-                             &error_fatal);
+    qdev_prop_set_uint64(DEVICE(xsrc), "flags", XIVE_SRC_STORE_EOI);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PNV_XIVE2_NR_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
      qdev_realize(DEVICE(xsrc), NULL, &local_err);
      if (local_err) {
          error_propagate(errp, local_err);
          return;
      }
 
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", PNV_XIVE2_NR_ENDS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", PNV_XIVE2_NR_ENDS);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
      qdev_realize(DEVICE(end_xsrc), NULL, &local_err);
      if (local_err) {
          error_propagate(errp, local_err);
hw/pci-host/pnv_phb3.c +3 -6
index 7a21497cf8..6da9053ffa 100644
@@ -1029,8 +1029,7 @@ static void pnv_phb3_realize(DeviceState *dev, Error **errp)
      /* LSI sources */
      object_property_set_link(OBJECT(&phb->lsis), "xics", OBJECT(pnv),
                               &error_abort);
-    object_property_set_int(OBJECT(&phb->lsis), "nr-irqs", PNV_PHB3_NUM_LSI,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&phb->lsis), "nr-irqs", PNV_PHB3_NUM_LSI);
      if (!qdev_realize(DEVICE(&phb->lsis), NULL, errp)) {
          return;
      }
@@ -1046,15 +1045,13 @@ static void pnv_phb3_realize(DeviceState *dev, Error **errp)
                               &error_abort);
      object_property_set_link(OBJECT(&phb->msis), "xics", OBJECT(pnv),
                               &error_abort);
-    object_property_set_int(OBJECT(&phb->msis), "nr-irqs", PHB3_MAX_MSI,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&phb->msis), "nr-irqs", PHB3_MAX_MSI);
      if (!qdev_realize(DEVICE(&phb->msis), NULL, errp)) {
          return;
      }
 
      /* Power Bus Common Queue */
-    object_property_set_link(OBJECT(&phb->pbcq), "phb", OBJECT(phb),
-                             &error_abort);
+    qdev_prop_set_link(DEVICE(&phb->pbcq), "phb", OBJECT(phb));
      if (!qdev_realize(DEVICE(&phb->pbcq), NULL, errp)) {
          return;
      }
hw/pci-host/pnv_phb4.c +2 -2
index ccbde841fc..c4e7cb0efe 100644
@@ -1583,8 +1583,8 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
      } else {
          nr_irqs = PNV_PHB4_MAX_INTs >> 1;
      }
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", nr_irqs, &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(phb), &error_fatal);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", nr_irqs);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(phb));
      if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
          return;
      }
hw/pci-host/pnv_phb4_pec.c +3 -7
index 43267a428f..9c21382330 100644
@@ -120,13 +120,9 @@ static void pnv_pec_default_phb_realize(PnvPhb4PecState *pec,
      int phb_id = pnv_phb4_pec_get_phb_id(pec, stack_no);
 
      object_property_add_child(OBJECT(pec), "phb[*]", OBJECT(phb));
-    object_property_set_link(OBJECT(phb), "pec", OBJECT(pec),
-                             &error_abort);
-    object_property_set_int(OBJECT(phb), "chip-id", pec->chip_id,
-                            &error_fatal);
-    object_property_set_int(OBJECT(phb), "index", phb_id,
-                            &error_fatal);
-
+    qdev_prop_set_link(DEVICE(phb), "pec", OBJECT(pec));
+    qdev_prop_set_uint32(DEVICE(phb), "chip-id", pec->chip_id);
+    qdev_prop_set_uint32(DEVICE(phb), "index", phb_id);
      if (!sysbus_realize(SYS_BUS_DEVICE(phb), errp)) {
          return;
      }
hw/ppc/pnv.c +17 -24
index 44b1fbbc93..7c6d5e4320 100644
@@ -954,35 +954,31 @@ static void pnv_init(MachineState *machine)
      pnv->chips = g_new0(PnvChip *, pnv->num_chips);
      for (i = 0; i < pnv->num_chips; i++) {
          char chip_name[32];
-        Object *chip = OBJECT(qdev_new(chip_typename));
+        DeviceState *chip = qdev_new(chip_typename);
          uint64_t chip_ram_size =  pnv_chip_get_ram_size(pnv, i);
 
          pnv->chips[i] = PNV_CHIP(chip);
 
+        snprintf(chip_name, sizeof(chip_name), "chip[%d]", i);
+        object_property_add_child(OBJECT(pnv), chip_name, OBJECT(chip));
+
          /* Distribute RAM among the chips  */
-        object_property_set_int(chip, "ram-start", chip_ram_start,
-                                &error_fatal);
-        object_property_set_int(chip, "ram-size", chip_ram_size,
-                                &error_fatal);
+        qdev_prop_set_uint64(chip, "ram-start", chip_ram_start);
+        qdev_prop_set_uint64(chip, "ram-size", chip_ram_size);
          chip_ram_start += chip_ram_size;
 
-        snprintf(chip_name, sizeof(chip_name), "chip[%d]", i);
-        object_property_add_child(OBJECT(pnv), chip_name, chip);
-        object_property_set_int(chip, "chip-id", i, &error_fatal);
-        object_property_set_int(chip, "nr-cores", machine->smp.cores,
-                                &error_fatal);
-        object_property_set_int(chip, "nr-threads", machine->smp.threads,
-                                &error_fatal);
+        qdev_prop_set_uint32(chip, "chip-id", i);
+        qdev_prop_set_uint32(chip, "nr-cores", machine->smp.cores);
+        qdev_prop_set_uint32(chip, "nr-threads", machine->smp.threads);
          /*
           * The POWER8 machine use the XICS interrupt interface.
           * Propagate the XICS fabric to the chip and its controllers.
           */
          if (object_dynamic_cast(OBJECT(pnv), TYPE_XICS_FABRIC)) {
-            object_property_set_link(chip, "xics", OBJECT(pnv), &error_abort);
+            qdev_prop_set_link(chip, "xics", OBJECT(pnv));
          }
          if (object_dynamic_cast(OBJECT(pnv), TYPE_XIVE_FABRIC)) {
-            object_property_set_link(chip, "xive-fabric", OBJECT(pnv),
-                                     &error_abort);
+            qdev_prop_set_link(chip, "xive-fabric", OBJECT(pnv));
          }
          sysbus_realize_and_unref(SYS_BUS_DEVICE(chip), &error_fatal);
      }
@@ -1492,7 +1488,7 @@ static void pnv_chip_quad_realize_one(PnvChip *chip, PnvQuad *eq,
                                         sizeof(*eq), TYPE_PNV_QUAD,
                                         &error_fatal, NULL);
 
-    object_property_set_int(OBJECT(eq), "quad-id", core_id, &error_fatal);
+    qdev_prop_set_uint32(DEVICE(eq), "quad-id", core_id);
      qdev_realize(DEVICE(eq), NULL, &error_fatal);
  }
 
@@ -1969,16 +1965,13 @@ static void pnv_chip_core_realize(PnvChip *chip, Error **errp)
          snprintf(core_name, sizeof(core_name), "core[%d]", core_hwid);
          object_property_add_child(OBJECT(chip), core_name, OBJECT(pnv_core));
          chip->cores[i] = pnv_core;
-        object_property_set_int(OBJECT(pnv_core), "nr-threads",
-                                chip->nr_threads, &error_fatal);
+        qdev_prop_set_uint32(DEVICE(pnv_core), "nr-threads", chip->nr_threads);
          object_property_set_int(OBJECT(pnv_core), CPU_CORE_PROP_CORE_ID,
                                  core_hwid, &error_fatal);
-        object_property_set_int(OBJECT(pnv_core), "pir",
-                                pcc->core_pir(chip, core_hwid), &error_fatal);
-        object_property_set_int(OBJECT(pnv_core), "hrmor", pnv->fw_load_addr,
-                                &error_fatal);
-        object_property_set_link(OBJECT(pnv_core), "chip", OBJECT(chip),
-                                 &error_abort);
+        qdev_prop_set_uint32(DEVICE(pnv_core), "pir",
+                             pcc->core_pir(chip, core_hwid));
+        qdev_prop_set_uint64(DEVICE(pnv_core), "hrmor", pnv->fw_load_addr);
+        qdev_prop_set_link(DEVICE(pnv_core), "chip", OBJECT(chip));
          qdev_realize(DEVICE(pnv_core), NULL, &error_fatal);
 
          /* Each core has an XSCOM MMIO region */
hw/ppc/pnv_psi.c +3 -7
index 8aa09ab26b..fb90d47138 100644
@@ -492,10 +492,7 @@ static void pnv_psi_power8_realize(DeviceState *dev, Error **errp)
      unsigned int i;
 
      /* Create PSI interrupt control source */
-    if (!object_property_set_int(OBJECT(ics), "nr-irqs", PSI_NUM_INTERRUPTS,
-                                 errp)) {
-        return;
-    }
+    qdev_prop_set_uint32(DEVICE(ics), "nr-irqs", PSI_NUM_INTERRUPTS);
      if (!qdev_realize(DEVICE(ics), NULL, errp)) {
          return;
      }
@@ -849,9 +846,8 @@ static void pnv_psi_power9_realize(DeviceState *dev, Error **errp)
      XiveSource *xsrc = &PNV9_PSI(psi)->source;
      int i;
 
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PSIHB9_NUM_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(psi), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PSIHB9_NUM_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(psi));
      if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
          return;
      }
Reviewed-by on v1 5/5
#12 lore raw

Re: [PATCH 5/5] hw/ppc/pnv: Set QDev properties using QDev API

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · 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.

One call in pnv_psi_power8_realize() propagate the Error* argument:

Quoted 8 lines
   if (!object_property_set_int(OBJECT(ics), "nr-irqs",
                                PSI_NUM_INTERRUPTS, errp)) {
       return;
   }

TYPE_ICS "nr-irqs" is declared in ics_properties[], itself always registered in ics_class_init(); so converting this errp to &error_abort is safe.

yes. That's ok. I think this model was one of the first I converted to QOM.

Quoted 6 lines

All other calls use either errp=&error_abort or &error_fatal, so converting to the QDev API is almost a no-op (QDev API always uses &error_abort).

Thanks,

C.

Quoted 246 lines
---
  hw/intc/pnv_xive.c         | 11 ++++------
  hw/intc/pnv_xive2.c        | 15 +++++---------
  hw/pci-host/pnv_phb3.c     |  9 +++------
  hw/pci-host/pnv_phb4.c     |  4 ++--
  hw/pci-host/pnv_phb4_pec.c | 10 +++-------
  hw/ppc/pnv.c               | 41 ++++++++++++++++----------------------
  hw/ppc/pnv_psi.c           | 10 +++-------
  7 files changed, 37 insertions(+), 63 deletions(-)
hw/intc/pnv_xive.c +4 -7
index 622f9d28b7..ccc1ea5380 100644
@@ -1857,17 +1857,14 @@ static void pnv_xive_realize(DeviceState *dev, Error **errp)
       * resized dynamically when the controller is configured by the FW
       * to limit accesses to resources not provisioned.
       */
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PNV_XIVE_NR_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PNV_XIVE_NR_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
      if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
          return;
      }
 
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", PNV_XIVE_NR_ENDS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", PNV_XIVE_NR_ENDS);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
      if (!qdev_realize(DEVICE(end_xsrc), NULL, errp)) {
          return;
      }
hw/intc/pnv_xive2.c +5 -10
index 7176d70234..d7695f65e7 100644
@@ -1821,22 +1821,17 @@ static void pnv_xive2_realize(DeviceState *dev, Error **errp)
       * resized dynamically when the controller is configured by the FW
       * to limit accesses to resources not provisioned.
       */
-    object_property_set_int(OBJECT(xsrc), "flags", XIVE_SRC_STORE_EOI,
-                            &error_fatal);
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PNV_XIVE2_NR_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive),
-                             &error_fatal);
+    qdev_prop_set_uint64(DEVICE(xsrc), "flags", XIVE_SRC_STORE_EOI);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PNV_XIVE2_NR_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(xive));
      qdev_realize(DEVICE(xsrc), NULL, &local_err);
      if (local_err) {
          error_propagate(errp, local_err);
          return;
      }
 
-    object_property_set_int(OBJECT(end_xsrc), "nr-ends", PNV_XIVE2_NR_ENDS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(end_xsrc), "nr-ends", PNV_XIVE2_NR_ENDS);
+    qdev_prop_set_link(DEVICE(end_xsrc), "xive", OBJECT(xive));
      qdev_realize(DEVICE(end_xsrc), NULL, &local_err);
      if (local_err) {
          error_propagate(errp, local_err);
hw/pci-host/pnv_phb3.c +3 -6
index 7a21497cf8..6da9053ffa 100644
@@ -1029,8 +1029,7 @@ static void pnv_phb3_realize(DeviceState *dev, Error **errp)
      /* LSI sources */
      object_property_set_link(OBJECT(&phb->lsis), "xics", OBJECT(pnv),
                               &error_abort);
-    object_property_set_int(OBJECT(&phb->lsis), "nr-irqs", PNV_PHB3_NUM_LSI,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&phb->lsis), "nr-irqs", PNV_PHB3_NUM_LSI);
      if (!qdev_realize(DEVICE(&phb->lsis), NULL, errp)) {
          return;
      }
@@ -1046,15 +1045,13 @@ static void pnv_phb3_realize(DeviceState *dev, Error **errp)
                               &error_abort);
      object_property_set_link(OBJECT(&phb->msis), "xics", OBJECT(pnv),
                               &error_abort);
-    object_property_set_int(OBJECT(&phb->msis), "nr-irqs", PHB3_MAX_MSI,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&phb->msis), "nr-irqs", PHB3_MAX_MSI);
      if (!qdev_realize(DEVICE(&phb->msis), NULL, errp)) {
          return;
      }
 
      /* Power Bus Common Queue */
-    object_property_set_link(OBJECT(&phb->pbcq), "phb", OBJECT(phb),
-                             &error_abort);
+    qdev_prop_set_link(DEVICE(&phb->pbcq), "phb", OBJECT(phb));
      if (!qdev_realize(DEVICE(&phb->pbcq), NULL, errp)) {
          return;
      }
hw/pci-host/pnv_phb4.c +2 -2
index ccbde841fc..c4e7cb0efe 100644
@@ -1583,8 +1583,8 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)
      } else {
          nr_irqs = PNV_PHB4_MAX_INTs >> 1;
      }
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", nr_irqs, &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(phb), &error_fatal);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", nr_irqs);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(phb));
      if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
          return;
      }
hw/pci-host/pnv_phb4_pec.c +3 -7
index 43267a428f..9c21382330 100644
@@ -120,13 +120,9 @@ static void pnv_pec_default_phb_realize(PnvPhb4PecState *pec,
      int phb_id = pnv_phb4_pec_get_phb_id(pec, stack_no);
 
      object_property_add_child(OBJECT(pec), "phb[*]", OBJECT(phb));
-    object_property_set_link(OBJECT(phb), "pec", OBJECT(pec),
-                             &error_abort);
-    object_property_set_int(OBJECT(phb), "chip-id", pec->chip_id,
-                            &error_fatal);
-    object_property_set_int(OBJECT(phb), "index", phb_id,
-                            &error_fatal);
-
+    qdev_prop_set_link(DEVICE(phb), "pec", OBJECT(pec));
+    qdev_prop_set_uint32(DEVICE(phb), "chip-id", pec->chip_id);
+    qdev_prop_set_uint32(DEVICE(phb), "index", phb_id);
      if (!sysbus_realize(SYS_BUS_DEVICE(phb), errp)) {
          return;
      }
hw/ppc/pnv.c +17 -24
index 44b1fbbc93..7c6d5e4320 100644
@@ -954,35 +954,31 @@ static void pnv_init(MachineState *machine)
      pnv->chips = g_new0(PnvChip *, pnv->num_chips);
      for (i = 0; i < pnv->num_chips; i++) {
          char chip_name[32];
-        Object *chip = OBJECT(qdev_new(chip_typename));
+        DeviceState *chip = qdev_new(chip_typename);
          uint64_t chip_ram_size =  pnv_chip_get_ram_size(pnv, i);
 
          pnv->chips[i] = PNV_CHIP(chip);
 
+        snprintf(chip_name, sizeof(chip_name), "chip[%d]", i);
+        object_property_add_child(OBJECT(pnv), chip_name, OBJECT(chip));
+
          /* Distribute RAM among the chips  */
-        object_property_set_int(chip, "ram-start", chip_ram_start,
-                                &error_fatal);
-        object_property_set_int(chip, "ram-size", chip_ram_size,
-                                &error_fatal);
+        qdev_prop_set_uint64(chip, "ram-start", chip_ram_start);
+        qdev_prop_set_uint64(chip, "ram-size", chip_ram_size);
          chip_ram_start += chip_ram_size;
 
-        snprintf(chip_name, sizeof(chip_name), "chip[%d]", i);
-        object_property_add_child(OBJECT(pnv), chip_name, chip);
-        object_property_set_int(chip, "chip-id", i, &error_fatal);
-        object_property_set_int(chip, "nr-cores", machine->smp.cores,
-                                &error_fatal);
-        object_property_set_int(chip, "nr-threads", machine->smp.threads,
-                                &error_fatal);
+        qdev_prop_set_uint32(chip, "chip-id", i);
+        qdev_prop_set_uint32(chip, "nr-cores", machine->smp.cores);
+        qdev_prop_set_uint32(chip, "nr-threads", machine->smp.threads);
          /*
           * The POWER8 machine use the XICS interrupt interface.
           * Propagate the XICS fabric to the chip and its controllers.
           */
          if (object_dynamic_cast(OBJECT(pnv), TYPE_XICS_FABRIC)) {
-            object_property_set_link(chip, "xics", OBJECT(pnv), &error_abort);
+            qdev_prop_set_link(chip, "xics", OBJECT(pnv));
          }
          if (object_dynamic_cast(OBJECT(pnv), TYPE_XIVE_FABRIC)) {
-            object_property_set_link(chip, "xive-fabric", OBJECT(pnv),
-                                     &error_abort);
+            qdev_prop_set_link(chip, "xive-fabric", OBJECT(pnv));
          }
          sysbus_realize_and_unref(SYS_BUS_DEVICE(chip), &error_fatal);
      }
@@ -1492,7 +1488,7 @@ static void pnv_chip_quad_realize_one(PnvChip *chip, PnvQuad *eq,
                                         sizeof(*eq), TYPE_PNV_QUAD,
                                         &error_fatal, NULL);
 
-    object_property_set_int(OBJECT(eq), "quad-id", core_id, &error_fatal);
+    qdev_prop_set_uint32(DEVICE(eq), "quad-id", core_id);
      qdev_realize(DEVICE(eq), NULL, &error_fatal);
  }
 
@@ -1969,16 +1965,13 @@ static void pnv_chip_core_realize(PnvChip *chip, Error **errp)
          snprintf(core_name, sizeof(core_name), "core[%d]", core_hwid);
          object_property_add_child(OBJECT(chip), core_name, OBJECT(pnv_core));
          chip->cores[i] = pnv_core;
-        object_property_set_int(OBJECT(pnv_core), "nr-threads",
-                                chip->nr_threads, &error_fatal);
+        qdev_prop_set_uint32(DEVICE(pnv_core), "nr-threads", chip->nr_threads);
          object_property_set_int(OBJECT(pnv_core), CPU_CORE_PROP_CORE_ID,
                                  core_hwid, &error_fatal);
-        object_property_set_int(OBJECT(pnv_core), "pir",
-                                pcc->core_pir(chip, core_hwid), &error_fatal);
-        object_property_set_int(OBJECT(pnv_core), "hrmor", pnv->fw_load_addr,
-                                &error_fatal);
-        object_property_set_link(OBJECT(pnv_core), "chip", OBJECT(chip),
-                                 &error_abort);
+        qdev_prop_set_uint32(DEVICE(pnv_core), "pir",
+                             pcc->core_pir(chip, core_hwid));
+        qdev_prop_set_uint64(DEVICE(pnv_core), "hrmor", pnv->fw_load_addr);
+        qdev_prop_set_link(DEVICE(pnv_core), "chip", OBJECT(chip));
          qdev_realize(DEVICE(pnv_core), NULL, &error_fatal);
 
          /* Each core has an XSCOM MMIO region */
hw/ppc/pnv_psi.c +3 -7
index 8aa09ab26b..fb90d47138 100644
@@ -492,10 +492,7 @@ static void pnv_psi_power8_realize(DeviceState *dev, Error **errp)
      unsigned int i;
 
      /* Create PSI interrupt control source */
-    if (!object_property_set_int(OBJECT(ics), "nr-irqs", PSI_NUM_INTERRUPTS,
-                                 errp)) {
-        return;
-    }
+    qdev_prop_set_uint32(DEVICE(ics), "nr-irqs", PSI_NUM_INTERRUPTS);
      if (!qdev_realize(DEVICE(ics), NULL, errp)) {
          return;
      }
@@ -849,9 +846,8 @@ static void pnv_psi_power9_realize(DeviceState *dev, Error **errp)
      XiveSource *xsrc = &PNV9_PSI(psi)->source;
      int i;
 
-    object_property_set_int(OBJECT(xsrc), "nr-irqs", PSIHB9_NUM_IRQS,
-                            &error_fatal);
-    object_property_set_link(OBJECT(xsrc), "xive", OBJECT(psi), &error_abort);
+    qdev_prop_set_uint32(DEVICE(xsrc), "nr-irqs", PSIHB9_NUM_IRQS);
+    qdev_prop_set_link(DEVICE(xsrc), "xive", OBJECT(psi));
      if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
          return;
      }
#13 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 19 lines · Philippe Mathieu-Daudé

part 1 [*] cover:
--
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. --

Quoted 2 lines

In this series PPC hw is converted. Only one call site in PNV forwards the Error* argument and its conversion is justified.

Feel free to take the 4 patches I acked via your tree when pushing it together with part 1/3.

I can't ack macio because that's Mark's turf.

Thanks,

Daniel

Quoted 35 lines

Based-on: <[email protected]>
(in particular [PATCH 02/19] hw/qdev: Introduce qdev_prop_set_link():
https://lore.kernel.org/qemu-devel/[email protected]/)

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (5):
hw/misc/macio: Set QDev properties using QDev API hw/pci-host/raven: Set QDev properties using QDev API hw/ppc/ppc4xx: Set QDev properties using QDev API hw/ppc/spapr: Set QDev properties using QDev API hw/ppc/pnv: Set QDev properties using QDev API

  hw/intc/pnv_xive.c         | 11 ++++------
  hw/intc/pnv_xive2.c        | 15 +++++---------
  hw/intc/spapr_xive.c       | 11 ++++------
  hw/intc/xics.c             |  4 ++--
  hw/intc/xive.c             |  4 ++--
  hw/misc/macio/macio.c      |  6 ++----
  hw/pci-host/pnv_phb3.c     |  9 +++------
  hw/pci-host/pnv_phb4.c     |  4 ++--
  hw/pci-host/pnv_phb4_pec.c | 10 +++-------
  hw/pci-host/raven.c        |  6 ++----
  hw/ppc/e500.c              |  3 +--
  hw/ppc/pnv.c               | 41 ++++++++++++++++----------------------
  hw/ppc/pnv_psi.c           | 10 +++-------
  hw/ppc/ppc405_boards.c     |  6 ++----
  hw/ppc/ppc405_uc.c         |  6 +++---
  hw/ppc/ppc440_bamboo.c     |  3 +--
  hw/ppc/ppc4xx_devs.c       |  2 +-
  hw/ppc/sam460ex.c          |  5 ++---
  hw/ppc/spapr_irq.c         |  8 +++-----
  19 files changed, 62 insertions(+), 102 deletions(-)
#14 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

part 1 [*] cover:
--
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.

6/8 years ago, we converted models to QOM, supposedly because the qdev interface was legacy and QOM was the new way. That's not true anymore ?

That said, I am ok with changes, even for the best practices. I would like to know how to keep track. Do we have a model skeleton/reference ?

Thanks,

C.

Quoted 44 lines

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. --

In this series PPC hw is converted. Only one call site in PNV forwards the Error* argument and its conversion is justified.

Based-on: <[email protected]>
(in particular [PATCH 02/19] hw/qdev: Introduce qdev_prop_set_link():
https://lore.kernel.org/qemu-devel/[email protected]/)

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (5):
hw/misc/macio: Set QDev properties using QDev API hw/pci-host/raven: Set QDev properties using QDev API hw/ppc/ppc4xx: Set QDev properties using QDev API hw/ppc/spapr: Set QDev properties using QDev API hw/ppc/pnv: Set QDev properties using QDev API

  hw/intc/pnv_xive.c         | 11 ++++------
  hw/intc/pnv_xive2.c        | 15 +++++---------
  hw/intc/spapr_xive.c       | 11 ++++------
  hw/intc/xics.c             |  4 ++--
  hw/intc/xive.c             |  4 ++--
  hw/misc/macio/macio.c      |  6 ++----
  hw/pci-host/pnv_phb3.c     |  9 +++------
  hw/pci-host/pnv_phb4.c     |  4 ++--
  hw/pci-host/pnv_phb4_pec.c | 10 +++-------
  hw/pci-host/raven.c        |  6 ++----
  hw/ppc/e500.c              |  3 +--
  hw/ppc/pnv.c               | 41 ++++++++++++++++----------------------
  hw/ppc/pnv_psi.c           | 10 +++-------
  hw/ppc/ppc405_boards.c     |  6 ++----
  hw/ppc/ppc405_uc.c         |  6 +++---
  hw/ppc/ppc440_bamboo.c     |  3 +--
  hw/ppc/ppc4xx_devs.c       |  2 +-
  hw/ppc/sam460ex.c          |  5 ++---
  hw/ppc/spapr_irq.c         |  8 +++-----
  19 files changed, 62 insertions(+), 102 deletions(-)
#15 lore raw
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines · Philippe Mathieu-Daudé

part 1 [*] cover:

Signature · 5 lines
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.
Quoted 6 lines
Quoted 3 lines

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

6/8 years ago, we converted models to QOM, supposedly because the qdev interface was legacy and QOM was the new way. That's not true anymore ?

That is a good question, and something that we really should decide first before going ahead with these changes. My understanding is that architectures with newer machines (particularly ARM and PPC) use QOM APIs directly, however more recently Markus did some improvements to qdev which largely eliminated the gap between the two. Hence why these days the two are mostly interchangeable: the main difference is that qdev has a notion of a parent which can be useful during device modelling.

Quoted 2 lines

That said, I am ok with changes, even for the best practices. I would like to know how to keep track. Do we have a model skeleton/reference ?

Agreed. I've added Peter on CC as I know he has had some thoughts on QOM vs. qdev, but certainly as a reviewer it would be great to know which way we should be heading in the future.

ATB,

Mark.

#16 lore raw
In reply to Cédric Le Goater
Quoted 13 lines · Cédric Le Goater
Quoted 11 lines · Philippe Mathieu-Daudé

part 1 [*] cover:

Signature · 9 lines
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.
Quoted 5 lines

6/8 years ago, we converted models to QOM, supposedly because the qdev interface was legacy and QOM was the new way. That's not true anymore ?

That said, I am ok with changes, even for the best practices. I would like to know how to keep track. Do we have a model skeleton/reference ?

I second all that.

Last year we spent a considerable amount of time figuring out how to properly use QOM in the pnv-phb controller, with a lot of code juggling to avoid using qdev directly. And it's not like we were doing something that was novel - the core hw/pci/pci.c files are filled with examples such as:

host_bridge = PCI_HOST_BRIDGE(rootbus->qbus.parent);

And this particular example (not accessing qbus.parent to get the parent bus) led to *a lot* of QOM code being added to allow the pnv_phb_root_port to access the parent bus because "you shouldn't access qdev in that way".

After all that, reading "There is no point in using the lower level QOM API with QDev; it makes the code more complex and harder to review." is funny. I know that there might be some nuance that I'm not aware of, and in the end what we did last year and what Phil is doing today are both steps in the same direction, but ATM this is confusing to me.

As Cedric said, I believe we should had a document laying out in a clear way when it is OK to use QDEV APIs and when it is OK to use QOM APIs. It would also be nice to document these (apparently) deprecated uses of these APIs that the core classes are doing.

Thanks,

Daniel

Quoted 50 lines

Thanks,

C.

Quoted 44 lines

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.

Signature · 36 lines
In this series PPC hw is converted. Only one call site in PNV
forwards the Error* argument and its conversion is justified.

Based-on: <[email protected]>
(in particular [PATCH 02/19] hw/qdev: Introduce qdev_prop_set_link():
  https://lore.kernel.org/qemu-devel/[email protected]/)

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (5):
   hw/misc/macio: Set QDev properties using QDev API
   hw/pci-host/raven: Set QDev properties using QDev API
   hw/ppc/ppc4xx: Set QDev properties using QDev API
   hw/ppc/spapr: Set QDev properties using QDev API
   hw/ppc/pnv: Set QDev properties using QDev API

  hw/intc/pnv_xive.c         | 11 ++++------
  hw/intc/pnv_xive2.c        | 15 +++++---------
  hw/intc/spapr_xive.c       | 11 ++++------
  hw/intc/xics.c             |  4 ++--
  hw/intc/xive.c             |  4 ++--
  hw/misc/macio/macio.c      |  6 ++----
  hw/pci-host/pnv_phb3.c     |  9 +++------
  hw/pci-host/pnv_phb4.c     |  4 ++--
  hw/pci-host/pnv_phb4_pec.c | 10 +++-------
  hw/pci-host/raven.c        |  6 ++----
  hw/ppc/e500.c              |  3 +--
  hw/ppc/pnv.c               | 41 ++++++++++++++++----------------------
  hw/ppc/pnv_psi.c           | 10 +++-------
  hw/ppc/ppc405_boards.c     |  6 ++----
  hw/ppc/ppc405_uc.c         |  6 +++---
  hw/ppc/ppc440_bamboo.c     |  3 +--
  hw/ppc/ppc4xx_devs.c       |  2 +-
  hw/ppc/sam460ex.c          |  5 ++---
  hw/ppc/spapr_irq.c         |  8 +++-----
  19 files changed, 62 insertions(+), 102 deletions(-)