Skip to contentSkip to conversation

QOM'ify PIIX southbridge creation

PATCH Superseded Bernhard Beschow 3 participants 26 messages May 28, 2022 – Jun 4, 2022

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover QOM'ify PIIX southbridge creation

v3:
* Rebase onto 'hw/acpi/piix4: remove legacy piix4_pm_init() function' (Mark) [1]
* Use embedded structs for touched PCI devices (Mark)
* Fix piix4's rtc embedded struct to be initialized by object_initialize_child() (Peter) [2]

Testing done:

1)
make check-avocado for --target-list=x86_64-softmmu,mips-softmmu
Result: All pass.

2)
* qemu-system-x86_64 -M pc -m 2G -cdrom archlinux-2022.05.01-x86_64.iso
* qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0"

In both cases the system booted successfully and it was possible to shut down the system using the poweroff command.

v2:
* Preserve DeviceState * as return value of piix4_create() (Mark)
* Aggregate all type name movements into first commit (Mark)
* Have piix4 southbridge rather than malta board instantiate piix4 pm (me)

Testing done:

1)
make check-avocado for --target-list=x86_64-softmmu,mips-softmmu
Result: All pass.

2)
Modify pci_piix3_realize() to start with

    error_setg(errp, "This is a test");

Then start qemu-system-x86_64 -M pc -m 1G -accel kvm -cpu host -cdrom archlinux-2022.05.01-x86_64.iso.
Result: qemu-system-x86_64 aborts with: "This is a test"

v1:
The piix3 and piix4 southbridge devices still rely on create() functions which are deprecated. This series resolves these functions piece by piece to modernize the code.

Both devices are modified in lockstep where possible to provide more context.

Testing done:
* qemu-system-x86_64 -M pc -m 2G -cdrom archlinux-2022.05.01-x86_64.iso
* qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0"

In both cases the system booted successfully and it was possible to shut down the system using the poweroff command.

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg05686.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg01128.html

Bernhard Beschow (7):
include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names hw/isa/piix4: Use object_initialize_child() for embedded struct hw/isa/piix{3,4}: Move pci_map_irq_fn's near pci_set_irq_fn's hw/isa/piix{3,4}: QOM'ify PCI device creation and wiring hw/isa/piix{3,4}: Factor out ISABus retrieval from create() functions hw/isa/piix4: QOM'ify PIIX4 PM creation
hw/isa/piix{3,4}: Inline and remove create() functions

 hw/i386/pc_piix.c             |   7 +-
 hw/isa/piix3.c                |  98 ++++++++++++++-------------
 hw/isa/piix4.c                | 120 +++++++++++++++++-----------------
 hw/mips/malta.c               |   7 +-
 include/hw/isa/isa.h          |   2 -
 include/hw/southbridge/piix.h |   6 +-
 6 files changed, 127 insertions(+), 113 deletions(-)
Signature · 1 line
2.36.1
#1 lore raw

PATCH v3 1/7 include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names

TYPE_PIIX3_PCI_DEVICE resides there as already, so add the remaining ones, too.

---
 hw/isa/piix3.c                | 3 ---
 include/hw/isa/isa.h          | 2 --
 include/hw/southbridge/piix.h | 4 ++++
 3 files changed, 4 insertions(+), 5 deletions(-)
hw/isa/piix3.c +0 -3
index dab901c9ad..d96ce2b788 100644
@@ -35,9 +35,6 @@
 
 #define XEN_PIIX_NUM_PIRQS      128ULL
 
-#define TYPE_PIIX3_DEVICE "PIIX3"
-#define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen"
-
 static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
 {
     qemu_set_irq(piix3->pic[pic_irq],
include/hw/isa/isa.h +0 -2
index 034d706ba1..e9fa2f5cea 100644
@@ -144,6 +144,4 @@ static inline ISABus *isa_bus_from_device(ISADevice *d)
     return ISA_BUS(qdev_get_parent_bus(DEVICE(d)));
 }
 
-#define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
-
 #endif
include/hw/southbridge/piix.h +4 -0
index 976b4da582..3b97186f75 100644
@@ -64,6 +64,10 @@ typedef struct PIIXState PIIX3State;
 DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
                          TYPE_PIIX3_PCI_DEVICE)
 
+#define TYPE_PIIX3_DEVICE "PIIX3"
+#define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen"
+#define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
+
 PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus);
 
 DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus);
Signature · 1 line
2.36.1
#2 lore raw

Re: [PATCH v3 1/7] include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names

Quoted 42 lines · Bernhard Beschow

TYPE_PIIX3_PCI_DEVICE resides there as already, so add the remaining ones, too.

---
  hw/isa/piix3.c                | 3 ---
  include/hw/isa/isa.h          | 2 --
  include/hw/southbridge/piix.h | 4 ++++
  3 files changed, 4 insertions(+), 5 deletions(-)
hw/isa/piix3.c +0 -3
index dab901c9ad..d96ce2b788 100644
@@ -35,9 +35,6 @@
 
  #define XEN_PIIX_NUM_PIRQS      128ULL
 
-#define TYPE_PIIX3_DEVICE "PIIX3"
-#define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen"
-
  static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
  {
      qemu_set_irq(piix3->pic[pic_irq],
include/hw/isa/isa.h +0 -2
index 034d706ba1..e9fa2f5cea 100644
@@ -144,6 +144,4 @@ static inline ISABus *isa_bus_from_device(ISADevice *d)
      return ISA_BUS(qdev_get_parent_bus(DEVICE(d)));
  }
 
-#define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
-
  #endif
include/hw/southbridge/piix.h +0 -0
index 976b4da582..3b97186f75 100644

include/hw/southbridge/piix.h typedef struct PIIXState PIIX3State; · line 73

Quoted 10 lines
include/hw/southbridge/piix.h +4 -0
@@ -64,6 +64,10 @@ typedef struct PIIXState PIIX3State;
  DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
                           TYPE_PIIX3_PCI_DEVICE)
 
+#define TYPE_PIIX3_DEVICE "PIIX3"
+#define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen"
+#define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
+
  PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus);
 
  DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus);

One tiny nit here: there's a typo in the subject line which I missed when reviewing v2.

s/soughbridge/southbridge/

ATB,

Mark.

#3 lore raw

Re: [PATCH v3 1/7] include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names

Quoted 55 lines · Mark Cave-Ayland

include/hw/isa/isa.h static inline ISABus *isa_bus_from_device(ISADevice

Quoted 31 lines · Bernhard Beschow

TYPE_PIIX3_PCI_DEVICE resides there as already, so add the remaining ones, too.

---
  hw/isa/piix3.c                | 3 ---
  include/hw/isa/isa.h          | 2 --
  include/hw/southbridge/piix.h | 4 ++++
  3 files changed, 4 insertions(+), 5 deletions(-)
hw/isa/piix3.c +0 -3
index dab901c9ad..d96ce2b788 100644
@@ -35,9 +35,6 @@
 
  #define XEN_PIIX_NUM_PIRQS      128ULL
 
-#define TYPE_PIIX3_DEVICE "PIIX3"
-#define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen"
-
  static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
  {
      qemu_set_irq(piix3->pic[pic_irq],
include/hw/isa/isa.h +0 -0
index 034d706ba1..e9fa2f5cea 100644
@@ -144,6 +144,4 @@ static inline ISABus *isa_bus_from_device(ISADevice

*d)

Review

Quoted 7 lines
include/hw/isa/isa.h +0 -2
      return ISA_BUS(qdev_get_parent_bus(DEVICE(d)));
  }
 
-#define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
-
  #endif
(quoted diff) +0 -0

b/include/hw/southbridge/piix.h

Quoted 13 lines

index 976b4da582..3b97186f75 100644

include/hw/southbridge/piix.h +4 -0
@@ -64,6 +64,10 @@ typedef struct PIIXState PIIX3State;
  DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
                           TYPE_PIIX3_PCI_DEVICE)
 
+#define TYPE_PIIX3_DEVICE "PIIX3"
+#define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen"
+#define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
+
  PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus);
 
Quoted 8 lines

include/hw/southbridge/piix.h typedef struct PIIXState PIIX3State; · line 73

Quoted 1 line
include/hw/southbridge/piix.h +0 -0
  DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus

**smbus);

One tiny nit here: there's a typo in the subject line which I missed when reviewing v2.

s/soughbridge/southbridge/

Ack. Will fix in v3.

Best regards,
Bernhard

Quoted 6 lines

ATB,

Mark.

#4 lore raw

Re: [PATCH v3 1/7] include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names

Quoted 19 lines · Bernhard Beschow

On Sun, May 29, 2022 at 11:05 AM Mark Cave-Ayland <[email protected] <mailto:[email protected]>> wrote:

On 28/05/2022 20:20, Bernhard Beschow wrote:

> TYPE_PIIX3_PCI_DEVICE resides there as already, so add the remaining > ones, too.
>
> Signed-off-by: Bernhard Beschow <[email protected]
<mailto:[email protected]>>
> Reviewed-by: Mark Cave-Ayland <[email protected]
<mailto:[email protected]>>
> Reviewed-by: Philippe Mathieu-Daudé <[email protected]
<mailto:[email protected]>>
> ---
>   hw/isa/piix3.c                | 3 ---
>   include/hw/isa/isa.h          | 2 --
>   include/hw/southbridge/piix.h | 4 ++++
>   3 files changed, 4 insertions(+), 5 deletions(-)

Quoted 7 lines

One tiny nit here: there's a typo in the subject line which I missed when reviewing v2.

s/soughbridge/southbridge/

Ack. Will fix in v3.

Can do. Also, "include/" in subject is not helpful.

#5 lore raw

Re: [PATCH v3 1/7] include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names

Am 30. Mai 2022 13:19:33 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 23 lines · Bernhard Beschow
Quoted 22 lines · On Sun, May 29, 2022 at 11:05 AM Mark Cave-Ayland…

On 28/05/2022 20:20, Bernhard Beschow wrote:

> TYPE_PIIX3_PCI_DEVICE resides there as already, so add the remaining > ones, too.
>
> Signed-off-by: Bernhard Beschow <[email protected]
<mailto:[email protected]>>
> Reviewed-by: Mark Cave-Ayland <[email protected]
<mailto:[email protected]>>
> Reviewed-by: Philippe Mathieu-Daudé <[email protected]
<mailto:[email protected]>>
> ---
>   hw/isa/piix3.c                | 3 ---
>   include/hw/isa/isa.h          | 2 --
>   include/hw/southbridge/piix.h | 4 ++++
>   3 files changed, 4 insertions(+), 5 deletions(-)

One tiny nit here: there's a typo in the subject line which I missed when reviewing v2.

Quoted 6 lines
Quoted 4 lines

s/soughbridge/southbridge/

Ack. Will fix in v3.

Can do. Also, "include/" in subject is not helpful.

I'll take care of this in v4.

Thanks,
Bernhard

#6 lore raw

PATCH v3 2/7 hw/isa/piix4: Use object_initialize_child() for embedded struct

In reply to Bernhard Beschow
---
 hw/isa/piix4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/isa/piix4.c +1 -1
index 9a6d981037..1d04fb6a55 100644
@@ -224,7 +224,7 @@ static void piix4_init(Object *obj)
 {
     PIIX4State *s = PIIX4_PCI_DEVICE(obj);
 
-    object_initialize(&s->rtc, sizeof(s->rtc), TYPE_MC146818_RTC);
+    object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
 }
 
 static void piix4_class_init(ObjectClass *klass, void *data)
Signature · 1 line
2.36.1
Reviewed-by Philippe Mathieu-Daudé on v3 2/7
#7 lore raw

Re: [PATCH v3 2/7] hw/isa/piix4: Use object_initialize_child() for embedded struct

Quoted 1 line · Bernhard Beschow

I suppose you refer to this thread:
https://lore.kernel.org/qemu-devel/CAFEAcA_y69=iXMH75dHeNkxMa038Z7Xk63GW9fdcAFHJSWS=sA@mail.gmail.com/

I'm going to change the tag to "Reported-by".

Quoted 18 lines
---
  hw/isa/piix4.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/isa/piix4.c +1 -1
index 9a6d981037..1d04fb6a55 100644
@@ -224,7 +224,7 @@ static void piix4_init(Object *obj)
  {
      PIIX4State *s = PIIX4_PCI_DEVICE(obj);
 
-    object_initialize(&s->rtc, sizeof(s->rtc), TYPE_MC146818_RTC);
+    object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
  }
 
  static void piix4_class_init(ObjectClass *klass, void *data)
#8 lore raw

Re: [PATCH v3 2/7] hw/isa/piix4: Use object_initialize_child() for embedded struct

Am 30. Mai 2022 11:38:30 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 5 lines · Bernhard Beschow
Quoted 1 line

I suppose you refer to this thread:
https://lore.kernel.org/qemu-devel/CAFEAcA_y69=iXMH75dHeNkxMa038Z7Xk63GW9fdcAFHJSWS=sA@mail.gmail.com/

Yes, correct.

Quoted 1 line

I'm going to change the tag to "Reported-by".

I'll take care of this in v4.

Quoted 18 lines
Quoted 16 lines
---
  hw/isa/piix4.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/isa/piix4.c +1 -0
index 9a6d981037..1d04fb6a55 100644
@@ -224,7 +224,7 @@ static void piix4_init(Object *obj)
  {
      PIIX4State *s = PIIX4_PCI_DEVICE(obj);
  -    object_initialize(&s->rtc, sizeof(s->rtc), TYPE_MC146818_RTC);
+    object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
  }
    static void piix4_class_init(ObjectClass *klass, void *data)
#9 lore raw

PATCH v3 3/7 hw/isa/piix{3, 4}: Move pci_map_irq_fn's near pci_set_irq_fn's

In reply to Bernhard Beschow

The pci_map_irq_fn's were implemented below type_init() which made them inaccessible to QOM functions. So move them up.

---
 hw/isa/piix3.c | 22 +++++++++++-----------
 hw/isa/piix4.c | 50 +++++++++++++++++++++++++-------------------------
 2 files changed, 36 insertions(+), 36 deletions(-)
hw/isa/piix3.c +11 -11
index d96ce2b788..c7a9014c3f 100644
@@ -78,6 +78,17 @@ static void piix3_set_irq(void *opaque, int pirq, int level)
     piix3_set_irq_level(piix3, pirq, level);
 }
 
+/*
+ * Return the global irq number corresponding to a given device irq
+ * pin. We could also use the bus number to have a more precise mapping.
+ */
+static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
+{
+    int slot_addend;
+    slot_addend = PCI_SLOT(pci_dev->devfn) - 1;
+    return (pci_intx + slot_addend) & 3;
+}
+
 static PCIINTxRoute piix3_route_intx_pin_to_irq(void *opaque, int pin)
 {
     PIIX3State *piix3 = opaque;
@@ -350,17 +361,6 @@ static void piix3_register_types(void)
 
 type_init(piix3_register_types)
 
-/*
- * Return the global irq number corresponding to a given device irq
- * pin. We could also use the bus number to have a more precise mapping.
- */
-static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
-{
-    int slot_addend;
-    slot_addend = PCI_SLOT(pci_dev->devfn) - 1;
-    return (pci_intx + slot_addend) & 3;
-}
-
 PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus)
 {
     PIIX3State *piix3;
hw/isa/piix4.c +25 -25

62 lines not on this page · raw message

Signature · 1 line
2.36.1
#10 lore raw

PATCH v3 4/7 hw/isa/piix{3, 4}: QOM'ify PCI device creation and wiring

In reply to Bernhard Beschow

PCI interrupt wiring and device creation (piix4 only) were performed in create() functions which are obsolete. Move these tasks into QOM functions to modernize the code.

In order to avoid duplicate checking for xen_enabled() the piix3 realize methods are now split.

---
 hw/isa/piix3.c | 67 +++++++++++++++++++++++++++++++++-----------------
 hw/isa/piix4.c | 30 ++++++++++++++++------
 2 files changed, 67 insertions(+), 30 deletions(-)
hw/isa/piix3.c +45 -22
index c7a9014c3f..de532cc692 100644
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/range.h"
+#include "qapi/error.h"
 #include "hw/southbridge/piix.h"
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
@@ -277,7 +278,7 @@ static const MemoryRegionOps rcr_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN
 };
 
-static void piix3_realize(PCIDevice *dev, Error **errp)
+static void pci_piix3_realize(PCIDevice *dev, Error **errp)
 {
     PIIX3State *d = PIIX3_PCI_DEVICE(dev);
 
@@ -302,7 +303,6 @@ static void pci_piix3_class_init(ObjectClass *klass, void *data)
     dc->desc        = "ISA bridge";
     dc->vmsd        = &vmstate_piix3;
     dc->hotpluggable   = false;
-    k->realize      = piix3_realize;
     k->vendor_id    = PCI_VENDOR_ID_INTEL;
     /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
     k->device_id    = PCI_DEVICE_ID_INTEL_82371SB_0;
@@ -326,11 +326,28 @@ static const TypeInfo piix3_pci_type_info = {
     },
 };
 
+static void piix3_realize(PCIDevice *dev, Error **errp)
+{
+    ERRP_GUARD();
+    PIIX3State *piix3 = PIIX3_PCI_DEVICE(dev);
+    PCIBus *pci_bus = pci_get_bus(dev);
+
+    pci_piix3_realize(dev, errp);
+    if (*errp) {
+        return;
+    }
+
+    pci_bus_irqs(pci_bus, piix3_set_irq, pci_slot_get_pirq,
+                 piix3, PIIX_NUM_PIRQS);
+    pci_bus_set_route_irq_fn(pci_bus, piix3_route_intx_pin_to_irq);
+};
+
 static void piix3_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->config_write = piix3_write_config;
+    k->realize = piix3_realize;
 }
 
 static const TypeInfo piix3_info = {
@@ -339,11 +356,33 @@ static const TypeInfo piix3_info = {
     .class_init    = piix3_class_init,
 };
 
+static void piix3_xen_realize(PCIDevice *dev, Error **errp)
+{
+    ERRP_GUARD();
+    PIIX3State *piix3 = PIIX3_PCI_DEVICE(dev);
+    PCIBus *pci_bus = pci_get_bus(dev);
+
+    pci_piix3_realize(dev, errp);
+    if (*errp) {
+        return;
+    }
+
+    /*
+     * Xen supports additional interrupt routes from the PCI devices to
+     * the IOAPIC: the four pins of each PCI device on the bus are also
+     * connected to the IOAPIC directly.
+     * These additional routes can be discovered through ACPI.
+     */
+    pci_bus_irqs(pci_bus, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+                 piix3, XEN_PIIX_NUM_PIRQS);
+};
+
 static void piix3_xen_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->config_write = piix3_write_config_xen;
+    k->realize = piix3_xen_realize;
 };
 
 static const TypeInfo piix3_xen_info = {
@@ -365,27 +404,11 @@ PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus)
 {
     PIIX3State *piix3;
     PCIDevice *pci_dev;
+    const char *type = xen_enabled() ? TYPE_PIIX3_XEN_DEVICE
+                                     : TYPE_PIIX3_DEVICE;
 
-    /*
-     * Xen supports additional interrupt routes from the PCI devices to
-     * the IOAPIC: the four pins of each PCI device on the bus are also
-     * connected to the IOAPIC directly.
-     * These additional routes can be discovered through ACPI.
-     */
-    if (xen_enabled()) {
-        pci_dev = pci_create_simple_multifunction(pci_bus, -1, true,
-                                                  TYPE_PIIX3_XEN_DEVICE);
-        piix3 = PIIX3_PCI_DEVICE(pci_dev);
-        pci_bus_irqs(pci_bus, xen_piix3_set_irq, xen_pci_slot_get_pirq,
-                     piix3, XEN_PIIX_NUM_PIRQS);
-    } else {
-        pci_dev = pci_create_simple_multifunction(pci_bus, -1, true,
-                                                  TYPE_PIIX3_DEVICE);
-        piix3 = PIIX3_PCI_DEVICE(pci_dev);
-        pci_bus_irqs(pci_bus, piix3_set_irq, pci_slot_get_pirq,
-                     piix3, PIIX_NUM_PIRQS);
-        pci_bus_set_route_irq_fn(pci_bus, piix3_route_intx_pin_to_irq);
-    }
+    pci_dev = pci_create_simple_multifunction(pci_bus, -1, true, type);
+    piix3 = PIIX3_PCI_DEVICE(pci_dev);
     *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0"));
 
     return piix3;
hw/isa/piix4.c +22 -8
index 18aa24424f..058bebb5e2 100644
@@ -35,6 +35,7 @@
 #include "hw/rtc/mc146818rtc.h"
 #include "hw/ide/pci.h"
 #include "hw/acpi/piix4.h"
+#include "hw/usb/hcd-uhci.h"
 #include "migration/vmstate.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
@@ -46,6 +47,8 @@ struct PIIX4State {
     qemu_irq *isa;
 
     RTCState rtc;
+    PCIIDEState ide;
+    UHCIState uhci;
     /* Reset Control Register */
     MemoryRegion rcr_mem;
     uint8_t rcr;
@@ -205,6 +208,7 @@ static const MemoryRegionOps piix4_rcr_ops = {
 static void piix4_realize(PCIDevice *dev, Error **errp)
 {
     PIIX4State *s = PIIX4_PCI_DEVICE(dev);
+    PCIBus *pci_bus = pci_get_bus(dev);
     ISABus *isa_bus;
     qemu_irq *i8259_out_irq;
 
@@ -243,6 +247,21 @@ static void piix4_realize(PCIDevice *dev, Error **errp)
         return;
     }
     s->rtc.irq = isa_get_irq(ISA_DEVICE(&s->rtc), s->rtc.isairq);
+
+    /* IDE */
+    qdev_prop_set_int32(DEVICE(&s->ide), "addr", dev->devfn + 1);
+    if (!qdev_realize(DEVICE(&s->ide), BUS(pci_bus), errp)) {
+        return;
+    }
+    pci_ide_create_devs(PCI_DEVICE(&s->ide));
+
+    /* USB */
+    qdev_prop_set_int32(DEVICE(&s->uhci), "addr", dev->devfn + 2);
+    if (!qdev_realize(DEVICE(&s->uhci), BUS(pci_bus), errp)) {
+        return;
+    }
+
+    pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s, PIIX_NUM_PIRQS);
 }
 
 static void piix4_init(Object *obj)
@@ -250,6 +269,8 @@ static void piix4_init(Object *obj)
     PIIX4State *s = PIIX4_PCI_DEVICE(obj);
 
     object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
+    object_initialize_child(obj, "ide", &s->ide, "piix4-ide");
+    object_initialize_child(obj, "uhci", &s->uhci, "piix4-usb-uhci");
 }
 
 static void piix4_class_init(ObjectClass *klass, void *data)
@@ -293,7 +314,6 @@ type_init(piix4_register_types)
 
 DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 {
-    PIIX4State *s;
     PCIDevice *pci;
     DeviceState *dev;
     int devfn = PCI_DEVFN(10, 0);
@@ -301,15 +321,11 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
     pci = pci_create_simple_multifunction(pci_bus, devfn,  true,
                                           TYPE_PIIX4_PCI_DEVICE);
     dev = DEVICE(pci);
-    s = PIIX4_PCI_DEVICE(pci);
+
     if (isa_bus) {
         *isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
     }
 
-    pci = pci_create_simple(pci_bus, devfn + 1, "piix4-ide");
-    pci_ide_create_devs(pci);
-
-    pci_create_simple(pci_bus, devfn + 2, "piix4-usb-uhci");
     if (smbus) {
         pci = pci_new(devfn + 3, TYPE_PIIX4_PM);
         qdev_prop_set_uint32(DEVICE(pci), "smb_io_base", 0x1100);
@@ -320,7 +336,5 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
         *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pci), "i2c"));
     }
 
-    pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s, PIIX_NUM_PIRQS);
-
     return dev;
 }
Signature · 1 line
2.36.1
Reviewed-by Philippe Mathieu-Daudé on v3 4/7
#11 lore raw

Re: [PATCH v3 4/7] hw/isa/piix{3, 4}: QOM'ify PCI device creation and wiring

Hi Bernhard,

Quoted 4 lines · Bernhard Beschow

PCI interrupt wiring and device creation (piix4 only) were performed in create() functions which are obsolete. Move these tasks into QOM functions to modernize the code.

Quoted 8 lines

In order to avoid duplicate checking for xen_enabled() the piix3 realize methods are now split.

---
  hw/isa/piix3.c | 67 +++++++++++++++++++++++++++++++++-----------------
  hw/isa/piix4.c | 30 ++++++++++++++++------
  2 files changed, 67 insertions(+), 30 deletions(-)

While this is the same chipset family, these models are maintained by different people... Do you mind splitting?

For PIIX4 part:

#12 lore raw

Re: [PATCH v3 4/7] hw/isa/piix{3,4}: QOM'ify PCI device creation and wiring

Am 30. Mai 2022 13:17:12 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 1 line

Hi Bernhard,

Hi Philippe,

Quoted 8 lines · Bernhard Beschow
Quoted 7 lines

PCI interrupt wiring and device creation (piix4 only) were performed in create() functions which are obsolete. Move these tasks into QOM functions to modernize the code.

In order to avoid duplicate checking for xen_enabled() the piix3 realize methods are now split.

Quoted 8 lines
Quoted 5 lines
---
  hw/isa/piix3.c | 67 +++++++++++++++++++++++++++++++++-----------------
  hw/isa/piix4.c | 30 ++++++++++++++++------
  2 files changed, 67 insertions(+), 30 deletions(-)

While this is the same chipset family, these models are maintained by different people... Do you mind splitting?

Will do. I'd split the whole series then.

Quoted 3 lines

For PIIX4 part:

#13 lore raw

PATCH v3 5/7 hw/isa/piix{3, 4}: Factor out ISABus retrieval from create() functions

In reply to Bernhard Beschow

Modernizes the code and even saves a few lines.

---
 hw/i386/pc_piix.c             | 3 ++-
 hw/isa/piix3.c                | 3 +--
 hw/isa/piix4.c                | 6 +-----
 hw/mips/malta.c               | 3 ++-
 include/hw/southbridge/piix.h | 4 ++--
 5 files changed, 8 insertions(+), 11 deletions(-)
hw/i386/pc_piix.c +2 -1
index 4120fd52e5..9d2076a7ca 100644
@@ -207,9 +207,10 @@ static void pc_init1(MachineState *machine,
                               pci_memory, ram_memory);
         pcms->bus = pci_bus;
 
-        piix3 = piix3_create(pci_bus, &isa_bus);
+        piix3 = piix3_create(pci_bus);
         piix3->pic = x86ms->gsi;
         piix3_devfn = piix3->dev.devfn;
+        isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0"));
     } else {
         pci_bus = NULL;
         i440fx_state = NULL;
hw/isa/piix3.c +1 -2
index de532cc692..c6ff7795f4 100644
@@ -400,7 +400,7 @@ static void piix3_register_types(void)
 
 type_init(piix3_register_types)
 
-PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus)
+PIIX3State *piix3_create(PCIBus *pci_bus)
 {
     PIIX3State *piix3;
     PCIDevice *pci_dev;
@@ -409,7 +409,6 @@ PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus)
 
     pci_dev = pci_create_simple_multifunction(pci_bus, -1, true, type);
     piix3 = PIIX3_PCI_DEVICE(pci_dev);
-    *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0"));
 
     return piix3;
 }
hw/isa/piix4.c +1 -5
index 058bebb5e2..96df21a610 100644
@@ -312,7 +312,7 @@ static void piix4_register_types(void)
 
 type_init(piix4_register_types)
 
-DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
+DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus)
 {
     PCIDevice *pci;
     DeviceState *dev;
@@ -322,10 +322,6 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
                                           TYPE_PIIX4_PCI_DEVICE);
     dev = DEVICE(pci);
 
-    if (isa_bus) {
-        *isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
-    }
-
     if (smbus) {
         pci = pci_new(devfn + 3, TYPE_PIIX4_PM);
         qdev_prop_set_uint32(DEVICE(pci), "smb_io_base", 0x1100);
hw/mips/malta.c +2 -1
index 9ffdc5b8f1..e446b25ad0 100644
@@ -1399,7 +1399,8 @@ void mips_malta_init(MachineState *machine)
     empty_slot_init("GT64120", 0, 0x20000000);
 
     /* Southbridge */
-    dev = piix4_create(pci_bus, &isa_bus, &smbus);
+    dev = piix4_create(pci_bus, &smbus);
+    isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
 
     /* Interrupt controller */
     qdev_connect_gpio_out_named(dev, "intr", 0, i8259_irq);
include/hw/southbridge/piix.h +2 -2
index 3b97186f75..0a2ef0c7b6 100644
@@ -68,8 +68,8 @@ DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
 #define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen"
 #define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
 
-PIIX3State *piix3_create(PCIBus *pci_bus, ISABus **isa_bus);
+PIIX3State *piix3_create(PCIBus *pci_bus);
 
-DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus);
+DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus);
 
 #endif
Signature · 1 line
2.36.1
#14 lore raw

PATCH v3 6/7 hw/isa/piix4: QOM'ify PIIX4 PM creation

In reply to Bernhard Beschow

Just like the real hardware, create the PIIX4 ACPI controller as part of the PIIX4 southbridge. This also mirrors how the IDE and USB functions are already created.

---
 hw/isa/piix4.c                | 25 ++++++++++++++-----------
 hw/mips/malta.c               |  3 ++-
 include/hw/southbridge/piix.h |  2 +-
 3 files changed, 17 insertions(+), 13 deletions(-)
hw/isa/piix4.c +14 -11
index 96df21a610..217989227d 100644
@@ -49,6 +49,7 @@ struct PIIX4State {
     RTCState rtc;
     PCIIDEState ide;
     UHCIState uhci;
+    PIIX4PMState pm;
     /* Reset Control Register */
     MemoryRegion rcr_mem;
     uint8_t rcr;
@@ -261,6 +262,14 @@ static void piix4_realize(PCIDevice *dev, Error **errp)
         return;
     }
 
+    /* ACPI controller */
+    qdev_prop_set_int32(DEVICE(&s->pm), "addr", dev->devfn + 3);
+    if (!qdev_realize(DEVICE(&s->pm), BUS(pci_bus), errp)) {
+        return;
+    }
+    qdev_connect_gpio_out(DEVICE(&s->pm), 0, s->isa[9]);
+    object_property_add_alias(OBJECT(s), "smbus", OBJECT(&s->pm), "i2c");
+
     pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s, PIIX_NUM_PIRQS);
 }
 
@@ -271,6 +280,10 @@ static void piix4_init(Object *obj)
     object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
     object_initialize_child(obj, "ide", &s->ide, "piix4-ide");
     object_initialize_child(obj, "uhci", &s->uhci, "piix4-usb-uhci");
+
+    object_initialize_child(obj, "pm", &s->pm, TYPE_PIIX4_PM);
+    qdev_prop_set_uint32(DEVICE(&s->pm), "smb_io_base", 0x1100);
+    qdev_prop_set_bit(DEVICE(&s->pm), "smm-enabled", 0);
 }
 
 static void piix4_class_init(ObjectClass *klass, void *data)
@@ -312,7 +325,7 @@ static void piix4_register_types(void)
 
 type_init(piix4_register_types)
 
-DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus)
+DeviceState *piix4_create(PCIBus *pci_bus)
 {
     PCIDevice *pci;
     DeviceState *dev;
@@ -322,15 +335,5 @@ DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus)
                                           TYPE_PIIX4_PCI_DEVICE);
     dev = DEVICE(pci);
 
-    if (smbus) {
-        pci = pci_new(devfn + 3, TYPE_PIIX4_PM);
-        qdev_prop_set_uint32(DEVICE(pci), "smb_io_base", 0x1100);
-        qdev_prop_set_bit(DEVICE(pci), "smm-enabled", 0);
-        pci_realize_and_unref(pci, pci_bus, &error_fatal);
-        qdev_connect_gpio_out(DEVICE(pci), 0,
-                              qdev_get_gpio_in_named(dev, "isa", 9));
-        *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pci), "i2c"));
-    }
-
     return dev;
 }
hw/mips/malta.c +2 -1
index e446b25ad0..b0fc84ccbb 100644
@@ -1399,8 +1399,9 @@ void mips_malta_init(MachineState *machine)
     empty_slot_init("GT64120", 0, 0x20000000);
 
     /* Southbridge */
-    dev = piix4_create(pci_bus, &smbus);
+    dev = piix4_create(pci_bus);
     isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
+    smbus = I2C_BUS(qdev_get_child_bus(dev, "smbus"));
 
     /* Interrupt controller */
     qdev_connect_gpio_out_named(dev, "intr", 0, i8259_irq);
include/hw/southbridge/piix.h +1 -1
index 0a2ef0c7b6..e1f5d6d5c8 100644
@@ -70,6 +70,6 @@ DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
 
 PIIX3State *piix3_create(PCIBus *pci_bus);
 
-DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus);
+DeviceState *piix4_create(PCIBus *pci_bus);
 
 #endif
Signature · 1 line
2.36.1
#15 lore raw

Re: [PATCH v3 6/7] hw/isa/piix4: QOM'ify PIIX4 PM creation

Quoted 24 lines · Bernhard Beschow

Just like the real hardware, create the PIIX4 ACPI controller as part of the PIIX4 southbridge. This also mirrors how the IDE and USB functions are already created.

---
  hw/isa/piix4.c                | 25 ++++++++++++++-----------
  hw/mips/malta.c               |  3 ++-
  include/hw/southbridge/piix.h |  2 +-
  3 files changed, 17 insertions(+), 13 deletions(-)
hw/isa/piix4.c +1 -0
index 96df21a610..217989227d 100644
@@ -49,6 +49,7 @@ struct PIIX4State {
      RTCState rtc;
      PCIIDEState ide;
      UHCIState uhci;
+    PIIX4PMState pm;
      /* Reset Control Register */
      MemoryRegion rcr_mem;
      uint8_t rcr;

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error **errp) · line 271

Quoted 10 lines
hw/isa/piix4.c +7 -0
@@ -261,6 +262,14 @@ static void piix4_realize(PCIDevice *dev, Error **errp)
          return;
      }
 
+    /* ACPI controller */
+    qdev_prop_set_int32(DEVICE(&s->pm), "addr", dev->devfn + 3);
+    if (!qdev_realize(DEVICE(&s->pm), BUS(pci_bus), errp)) {
+        return;
+    }
+    qdev_connect_gpio_out(DEVICE(&s->pm), 0, s->isa[9]);
+    object_property_add_alias(OBJECT(s), "smbus", OBJECT(&s->pm), "i2c");

Now that the PM device is QOMified you don't actually need this alias anymore (see below). In general aliasing parts of contained devices onto the container isn't recommended, since it starts to blur the line between individual devices and then you find some wiring gets done to the container, some directly to the contained device and then it starts to get confusing quite quickly.

Quoted 44 lines
hw/isa/piix4.c +5 -11
      pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s, PIIX_NUM_PIRQS);
  }
 
@@ -271,6 +280,10 @@ static void piix4_init(Object *obj)
      object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
      object_initialize_child(obj, "ide", &s->ide, "piix4-ide");
      object_initialize_child(obj, "uhci", &s->uhci, "piix4-usb-uhci");
+
+    object_initialize_child(obj, "pm", &s->pm, TYPE_PIIX4_PM);
+    qdev_prop_set_uint32(DEVICE(&s->pm), "smb_io_base", 0x1100);
+    qdev_prop_set_bit(DEVICE(&s->pm), "smm-enabled", 0);
  }
 
  static void piix4_class_init(ObjectClass *klass, void *data)
@@ -312,7 +325,7 @@ static void piix4_register_types(void)
 
  type_init(piix4_register_types)
 
-DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus)
+DeviceState *piix4_create(PCIBus *pci_bus)
  {
      PCIDevice *pci;
      DeviceState *dev;
@@ -322,15 +335,5 @@ DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus)
                                            TYPE_PIIX4_PCI_DEVICE);
      dev = DEVICE(pci);
 
-    if (smbus) {
-        pci = pci_new(devfn + 3, TYPE_PIIX4_PM);
-        qdev_prop_set_uint32(DEVICE(pci), "smb_io_base", 0x1100);
-        qdev_prop_set_bit(DEVICE(pci), "smm-enabled", 0);
-        pci_realize_and_unref(pci, pci_bus, &error_fatal);
-        qdev_connect_gpio_out(DEVICE(pci), 0,
-                              qdev_get_gpio_in_named(dev, "isa", 9));
-        *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pci), "i2c"));
-    }
-
      return dev;
  }
hw/mips/malta.c +0 -0
index e446b25ad0..b0fc84ccbb 100644

hw/mips/malta.c void mips_malta_init(MachineState *machine) · line 1404

Quoted 7 lines
hw/mips/malta.c +2 -1
@@ -1399,8 +1399,9 @@ void mips_malta_init(MachineState *machine)
      empty_slot_init("GT64120", 0, 0x20000000);
 
      /* Southbridge */
-    dev = piix4_create(pci_bus, &smbus);
+    dev = piix4_create(pci_bus);
      isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
+    smbus = I2C_BUS(qdev_get_child_bus(dev, "smbus"));

It should now be possible to do something like this:

    pm_dev = DEVICE(object_resolve_path_component(OBJECT(dev), "pm"));
    smbus = I2C_BUS(qdev_get_child_bus(pm_dev, "i2c"));

whereby we grab the reference to the PIIX4_PM device by resolving the "pm" child object and then use that to obtain the reference to smbus.

Quoted 7 lines
hw/mips/malta.c +0 -0
      /* Interrupt controller */
      qdev_connect_gpio_out_named(dev, "intr", 0, i8259_irq);
include/hw/southbridge/piix.h +0 -0
index 0a2ef0c7b6..e1f5d6d5c8 100644

include/hw/southbridge/piix.h DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE, · line 75

Quoted 7 lines
include/hw/southbridge/piix.h +1 -1
@@ -70,6 +70,6 @@ DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
 
  PIIX3State *piix3_create(PCIBus *pci_bus);
 
-DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus);
+DeviceState *piix4_create(PCIBus *pci_bus);
 
  #endif

ATB,

Mark.

#16 lore raw

Re: [PATCH v3 6/7] hw/isa/piix4: QOM'ify PIIX4 PM creation

Quoted 105 lines · Mark Cave-Ayland

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error

Quoted 24 lines · Bernhard Beschow

Just like the real hardware, create the PIIX4 ACPI controller as part of the PIIX4 southbridge. This also mirrors how the IDE and USB functions are already created.

---
  hw/isa/piix4.c                | 25 ++++++++++++++-----------
  hw/mips/malta.c               |  3 ++-
  include/hw/southbridge/piix.h |  2 +-
  3 files changed, 17 insertions(+), 13 deletions(-)
hw/isa/piix4.c +1 -0
index 96df21a610..217989227d 100644
@@ -49,6 +49,7 @@ struct PIIX4State {
      RTCState rtc;
      PCIIDEState ide;
      UHCIState uhci;
+    PIIX4PMState pm;
      /* Reset Control Register */
      MemoryRegion rcr_mem;
      uint8_t rcr;
@@ -261,6 +262,14 @@ static void piix4_realize(PCIDevice *dev, Error

**errp)

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error **errp)

Quoted 10 lines
hw/isa/piix4.c +7 -0
          return;
      }
 
+    /* ACPI controller */
+    qdev_prop_set_int32(DEVICE(&s->pm), "addr", dev->devfn + 3);
+    if (!qdev_realize(DEVICE(&s->pm), BUS(pci_bus), errp)) {
+        return;
+    }
+    qdev_connect_gpio_out(DEVICE(&s->pm), 0, s->isa[9]);
+    object_property_add_alias(OBJECT(s), "smbus", OBJECT(&s->pm),

"i2c");

Now that the PM device is QOMified you don't actually need this alias anymore (see
below). In general aliasing parts of contained devices onto the container isn't
recommended, since it starts to blur the line between individual devices and then you
find some wiring gets done to the container, some directly to the contained device
and then it starts to get confusing quite quickly.

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error · line 272

Quoted 1 line
hw/isa/piix4.c +0 -0
      pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s,

PIIX_NUM_PIRQS);

hw/isa/piix4.c DeviceState *piix4_create(PCIBus *pci_bus, I2CBus

Quoted 23 lines
hw/isa/piix4.c +5 -1
  }
 
@@ -271,6 +280,10 @@ static void piix4_init(Object *obj)
      object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
      object_initialize_child(obj, "ide", &s->ide, "piix4-ide");
      object_initialize_child(obj, "uhci", &s->uhci, "piix4-usb-uhci");
+
+    object_initialize_child(obj, "pm", &s->pm, TYPE_PIIX4_PM);
+    qdev_prop_set_uint32(DEVICE(&s->pm), "smb_io_base", 0x1100);
+    qdev_prop_set_bit(DEVICE(&s->pm), "smm-enabled", 0);
  }
 
  static void piix4_class_init(ObjectClass *klass, void *data)
@@ -312,7 +325,7 @@ static void piix4_register_types(void)
 
  type_init(piix4_register_types)
 
-DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus)
+DeviceState *piix4_create(PCIBus *pci_bus)
  {
      PCIDevice *pci;
      DeviceState *dev;
@@ -322,15 +335,5 @@ DeviceState *piix4_create(PCIBus *pci_bus, I2CBus

**smbus)

Quoted 20 lines
hw/isa/piix4.c +0 -10
                                            TYPE_PIIX4_PCI_DEVICE);
      dev = DEVICE(pci);
 
-    if (smbus) {
-        pci = pci_new(devfn + 3, TYPE_PIIX4_PM);
-        qdev_prop_set_uint32(DEVICE(pci), "smb_io_base", 0x1100);
-        qdev_prop_set_bit(DEVICE(pci), "smm-enabled", 0);
-        pci_realize_and_unref(pci, pci_bus, &error_fatal);
-        qdev_connect_gpio_out(DEVICE(pci), 0,
-                              qdev_get_gpio_in_named(dev, "isa", 9));
-        *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pci), "i2c"));
-    }
-
      return dev;
  }
hw/mips/malta.c +0 -0
index e446b25ad0..b0fc84ccbb 100644

hw/mips/malta.c void mips_malta_init(MachineState *machine) · line 1404

Quoted 7 lines
hw/mips/malta.c +2 -1
@@ -1399,8 +1399,9 @@ void mips_malta_init(MachineState *machine)
      empty_slot_init("GT64120", 0, 0x20000000);
 
      /* Southbridge */
-    dev = piix4_create(pci_bus, &smbus);
+    dev = piix4_create(pci_bus);
      isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
+    smbus = I2C_BUS(qdev_get_child_bus(dev, "smbus"));

It should now be possible to do something like this:

Quoted 7 lines
     pm_dev = DEVICE(object_resolve_path_component(OBJECT(dev), "pm"));
     smbus = I2C_BUS(qdev_get_child_bus(pm_dev, "i2c"));

whereby we grab the reference to the PIIX4_PM device by resolving the "pm" child
object and then use that to obtain the reference to smbus.

Imagining the container device to be an abstraction layer for the contained functionality I actually prefer the alias. Having it one doesn't need to know that there is an internal device named "pm" and one doesn't need to care about how many levels deep it is buried inside the implementation. This allows for further refactoring the PIIX4 without breaking its contract to its users.

Also, this reflects how the real hardware works: The Malta board can wire up the PIIX4 southbridge without worrying about its inner details. One can look into the datasheets, see the exposed interfaces and pins, and connect them. By QOM'ifying PIIX4 we now have the opportunity to mirror the real hardware by exposing it to the Malta board as a black box which exposes dedicated pins and buses.

Looking further into the QEMU code, there is even the following comment in sabrelite.c:
/*
* TODO: Ideally we would expose the chip select and spi bus on the
* SoC object using alias properties; then we would not need to
* directly access the underlying spi device object.
*/
To me this comment seems that the authors think in a similar way.

What do you think?

Best regards,
Bernhard

Quoted 21 lines

Review

Quoted 3 lines
hw/mips/malta.c +0 -0
      /* Interrupt controller */
      qdev_connect_gpio_out_named(dev, "intr", 0, i8259_irq);
(quoted diff) +0 -0

b/include/hw/southbridge/piix.h

include/hw/southbridge/piix.h DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE, · line 75

Quoted 11 lines

index 0a2ef0c7b6..e1f5d6d5c8 100644

include/hw/southbridge/piix.h +1 -1
@@ -70,6 +70,6 @@ DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
 
  PIIX3State *piix3_create(PCIBus *pci_bus);
 
-DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus);
+DeviceState *piix4_create(PCIBus *pci_bus);
 
  #endif

ATB,

Mark.

#17 lore raw

Re: [PATCH v3 6/7] hw/isa/piix4: QOM'ify PIIX4 PM creation

Quoted 123 lines · Bernhard Beschow
Quoted 105 lines · Mark Cave-Ayland

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error

Quoted 24 lines · Bernhard Beschow

Just like the real hardware, create the PIIX4 ACPI controller as part of the PIIX4 southbridge. This also mirrors how the IDE and USB functions are already created.

---
   hw/isa/piix4.c                | 25 ++++++++++++++-----------
   hw/mips/malta.c               |  3 ++-
   include/hw/southbridge/piix.h |  2 +-
   3 files changed, 17 insertions(+), 13 deletions(-)
hw/isa/piix4.c +1 -0
index 96df21a610..217989227d 100644
@@ -49,6 +49,7 @@ struct PIIX4State {
       RTCState rtc;
       PCIIDEState ide;
       UHCIState uhci;
+    PIIX4PMState pm;
       /* Reset Control Register */
       MemoryRegion rcr_mem;
       uint8_t rcr;
@@ -261,6 +262,14 @@ static void piix4_realize(PCIDevice *dev, Error

**errp)

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error **errp)

Quoted 10 lines
hw/isa/piix4.c +7 -0
           return;
       }
 
+    /* ACPI controller */
+    qdev_prop_set_int32(DEVICE(&s->pm), "addr", dev->devfn + 3);
+    if (!qdev_realize(DEVICE(&s->pm), BUS(pci_bus), errp)) {
+        return;
+    }
+    qdev_connect_gpio_out(DEVICE(&s->pm), 0, s->isa[9]);
+    object_property_add_alias(OBJECT(s), "smbus", OBJECT(&s->pm),

"i2c");

Now that the PM device is QOMified you don't actually need this alias anymore (see
below). In general aliasing parts of contained devices onto the container isn't
recommended, since it starts to blur the line between individual devices and then you
find some wiring gets done to the container, some directly to the contained device
and then it starts to get confusing quite quickly.

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error · line 272

Quoted 1 line
hw/isa/piix4.c +0 -0
       pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s,

PIIX_NUM_PIRQS);

hw/isa/piix4.c DeviceState *piix4_create(PCIBus *pci_bus, I2CBus

Quoted 23 lines
hw/isa/piix4.c +5 -1
   }
 
@@ -271,6 +280,10 @@ static void piix4_init(Object *obj)
       object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
       object_initialize_child(obj, "ide", &s->ide, "piix4-ide");
       object_initialize_child(obj, "uhci", &s->uhci, "piix4-usb-uhci");
+
+    object_initialize_child(obj, "pm", &s->pm, TYPE_PIIX4_PM);
+    qdev_prop_set_uint32(DEVICE(&s->pm), "smb_io_base", 0x1100);
+    qdev_prop_set_bit(DEVICE(&s->pm), "smm-enabled", 0);
   }
 
   static void piix4_class_init(ObjectClass *klass, void *data)
@@ -312,7 +325,7 @@ static void piix4_register_types(void)
 
   type_init(piix4_register_types)
 
-DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus)
+DeviceState *piix4_create(PCIBus *pci_bus)
   {
       PCIDevice *pci;
       DeviceState *dev;
@@ -322,15 +335,5 @@ DeviceState *piix4_create(PCIBus *pci_bus, I2CBus

**smbus)

Quoted 20 lines
hw/isa/piix4.c +0 -10
                                             TYPE_PIIX4_PCI_DEVICE);
       dev = DEVICE(pci);
 
-    if (smbus) {
-        pci = pci_new(devfn + 3, TYPE_PIIX4_PM);
-        qdev_prop_set_uint32(DEVICE(pci), "smb_io_base", 0x1100);
-        qdev_prop_set_bit(DEVICE(pci), "smm-enabled", 0);
-        pci_realize_and_unref(pci, pci_bus, &error_fatal);
-        qdev_connect_gpio_out(DEVICE(pci), 0,
-                              qdev_get_gpio_in_named(dev, "isa", 9));
-        *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pci), "i2c"));
-    }
-
       return dev;
   }
hw/mips/malta.c +0 -0
index e446b25ad0..b0fc84ccbb 100644

hw/mips/malta.c void mips_malta_init(MachineState *machine) · line 1404

Quoted 7 lines
hw/mips/malta.c +2 -1
@@ -1399,8 +1399,9 @@ void mips_malta_init(MachineState *machine)
       empty_slot_init("GT64120", 0, 0x20000000);
 
       /* Southbridge */
-    dev = piix4_create(pci_bus, &smbus);
+    dev = piix4_create(pci_bus);
       isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
+    smbus = I2C_BUS(qdev_get_child_bus(dev, "smbus"));

It should now be possible to do something like this:

Quoted 7 lines
      pm_dev = DEVICE(object_resolve_path_component(OBJECT(dev), "pm"));
      smbus = I2C_BUS(qdev_get_child_bus(pm_dev, "i2c"));

whereby we grab the reference to the PIIX4_PM device by resolving the "pm" child
object and then use that to obtain the reference to smbus.

Imagining the container device to be an abstraction layer for the contained functionality I actually prefer the alias. Having it one doesn't need to know that there is an internal device named "pm" and one doesn't need to care about how many levels deep it is buried inside the implementation. This allows for further refactoring the PIIX4 without breaking its contract to its users.

Quoted 6 lines

Also, this reflects how the real hardware works: The Malta board can wire up the PIIX4 southbridge without worrying about its inner details. One can look into the datasheets, see the exposed interfaces and pins, and connect them. By QOM'ifying PIIX4 we now have the opportunity to mirror the real hardware by exposing it to the Malta board as a black box which exposes dedicated pins and buses.

It's a bit trickier in this particular case because here the PIIX4 device acts as both a container and PCI device instance - and certainly the distinction can be blurred when modelling integrated devices.

The reason for leaning towards referencing the "pm" child object directly is because a quick glance at the datasheet suggests that the PM functions and smbus are exposed via function 3, so it feels that referencing that PCIDevice instance to find the smbus is intuitive.

For me using the "pm" child object is a shorter alternative to using pci_find_device() to locate the function 3 PCIDevice function on the bus, which is effectively what a guest OS would do. Since the PM device sits directly on the PCI bus it would never change depth within the PIIX4 container device, and renaming child object properties is an extremely rare event (which would also be easily fixable with grep).

Quoted 10 lines

Looking further into the QEMU code, there is even the following comment in sabrelite.c:
/*
* TODO: Ideally we would expose the chip select and spi bus on the
* SoC object using alias properties; then we would not need to
* directly access the underlying spi device object.
*/
To me this comment seems that the authors think in a similar way.

What do you think?

It's difficult for me to know without having much knowledge of ARM devices, but I can see how this might be useful given that SoCs can integrate a lot of different devices into a single address space. Another thing to note is that the comment above was originally written in 2016, and the qdev/QOM APIs (and indeed our knowledge as to how best to use them) have improved considerably since then.

ATB,

Mark.

#18 lore raw

Re: [PATCH v3 6/7] hw/isa/piix4: QOM'ify PIIX4 PM creation

Am 30. Mai 2022 19:58:37 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 132 lines · Bernhard Beschow
Quoted 124 lines
Quoted 105 lines · Mark Cave-Ayland

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error

Quoted 24 lines · Bernhard Beschow

Just like the real hardware, create the PIIX4 ACPI controller as part of the PIIX4 southbridge. This also mirrors how the IDE and USB functions are already created.

---
   hw/isa/piix4.c                | 25 ++++++++++++++-----------
   hw/mips/malta.c               |  3 ++-
   include/hw/southbridge/piix.h |  2 +-
   3 files changed, 17 insertions(+), 13 deletions(-)
hw/isa/piix4.c +1 -0
index 96df21a610..217989227d 100644
@@ -49,6 +49,7 @@ struct PIIX4State {
       RTCState rtc;
       PCIIDEState ide;
       UHCIState uhci;
+    PIIX4PMState pm;
       /* Reset Control Register */
       MemoryRegion rcr_mem;
       uint8_t rcr;
@@ -261,6 +262,14 @@ static void piix4_realize(PCIDevice *dev, Error

**errp)

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error **errp)

Quoted 10 lines
hw/isa/piix4.c +7 -0
           return;
       }
 
+    /* ACPI controller */
+    qdev_prop_set_int32(DEVICE(&s->pm), "addr", dev->devfn + 3);
+    if (!qdev_realize(DEVICE(&s->pm), BUS(pci_bus), errp)) {
+        return;
+    }
+    qdev_connect_gpio_out(DEVICE(&s->pm), 0, s->isa[9]);
+    object_property_add_alias(OBJECT(s), "smbus", OBJECT(&s->pm),

"i2c");

Now that the PM device is QOMified you don't actually need this alias anymore (see
below). In general aliasing parts of contained devices onto the container isn't
recommended, since it starts to blur the line between individual devices and then you
find some wiring gets done to the container, some directly to the contained device
and then it starts to get confusing quite quickly.

hw/isa/piix4.c static void piix4_realize(PCIDevice *dev, Error · line 272

Quoted 1 line
hw/isa/piix4.c +0 -0
       pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s,

PIIX_NUM_PIRQS);

hw/isa/piix4.c DeviceState *piix4_create(PCIBus *pci_bus, I2CBus

Quoted 23 lines
hw/isa/piix4.c +5 -1
   }
 
@@ -271,6 +280,10 @@ static void piix4_init(Object *obj)
       object_initialize_child(obj, "rtc", &s->rtc, TYPE_MC146818_RTC);
       object_initialize_child(obj, "ide", &s->ide, "piix4-ide");
       object_initialize_child(obj, "uhci", &s->uhci, "piix4-usb-uhci");
+
+    object_initialize_child(obj, "pm", &s->pm, TYPE_PIIX4_PM);
+    qdev_prop_set_uint32(DEVICE(&s->pm), "smb_io_base", 0x1100);
+    qdev_prop_set_bit(DEVICE(&s->pm), "smm-enabled", 0);
   }
 
   static void piix4_class_init(ObjectClass *klass, void *data)
@@ -312,7 +325,7 @@ static void piix4_register_types(void)
 
   type_init(piix4_register_types)
 
-DeviceState *piix4_create(PCIBus *pci_bus, I2CBus **smbus)
+DeviceState *piix4_create(PCIBus *pci_bus)
   {
       PCIDevice *pci;
       DeviceState *dev;
@@ -322,15 +335,5 @@ DeviceState *piix4_create(PCIBus *pci_bus, I2CBus

**smbus)

Quoted 20 lines
hw/isa/piix4.c +0 -10
                                             TYPE_PIIX4_PCI_DEVICE);
       dev = DEVICE(pci);
 
-    if (smbus) {
-        pci = pci_new(devfn + 3, TYPE_PIIX4_PM);
-        qdev_prop_set_uint32(DEVICE(pci), "smb_io_base", 0x1100);
-        qdev_prop_set_bit(DEVICE(pci), "smm-enabled", 0);
-        pci_realize_and_unref(pci, pci_bus, &error_fatal);
-        qdev_connect_gpio_out(DEVICE(pci), 0,
-                              qdev_get_gpio_in_named(dev, "isa", 9));
-        *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pci), "i2c"));
-    }
-
       return dev;
   }
hw/mips/malta.c +0 -0
index e446b25ad0..b0fc84ccbb 100644

hw/mips/malta.c void mips_malta_init(MachineState *machine) · line 1404

Quoted 7 lines
hw/mips/malta.c +2 -1
@@ -1399,8 +1399,9 @@ void mips_malta_init(MachineState *machine)
       empty_slot_init("GT64120", 0, 0x20000000);
 
       /* Southbridge */
-    dev = piix4_create(pci_bus, &smbus);
+    dev = piix4_create(pci_bus);
       isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
+    smbus = I2C_BUS(qdev_get_child_bus(dev, "smbus"));

It should now be possible to do something like this:

Quoted 7 lines
      pm_dev = DEVICE(object_resolve_path_component(OBJECT(dev), "pm"));
      smbus = I2C_BUS(qdev_get_child_bus(pm_dev, "i2c"));

whereby we grab the reference to the PIIX4_PM device by resolving the "pm" child
object and then use that to obtain the reference to smbus.

Imagining the container device to be an abstraction layer for the contained functionality I actually prefer the alias. Having it one doesn't need to know that there is an internal device named "pm" and one doesn't need to care about how many levels deep it is buried inside the implementation. This allows for further refactoring the PIIX4 without breaking its contract to its users.

Quoted 6 lines

Also, this reflects how the real hardware works: The Malta board can wire up the PIIX4 southbridge without worrying about its inner details. One can look into the datasheets, see the exposed interfaces and pins, and connect them. By QOM'ifying PIIX4 we now have the opportunity to mirror the real hardware by exposing it to the Malta board as a black box which exposes dedicated pins and buses.

Quoted 5 lines

It's a bit trickier in this particular case because here the PIIX4 device acts as both a container and PCI device instance - and certainly the distinction can be blurred when modelling integrated devices.

The reason for leaning towards referencing the "pm" child object directly is because a quick glance at the datasheet suggests that the PM functions and smbus are exposed via function 3, so it feels that referencing that PCIDevice instance to find the smbus is intuitive.

For me using the "pm" child object is a shorter alternative to using pci_find_device() to locate the function 3 PCIDevice function on the bus, which is effectively what a guest OS would do. Since the PM device sits directly on the PCI bus it would never change depth within the PIIX4 container device, and renaming child object properties is an extremely rare event (which would also be easily fixable with grep).

Alright, I'll implement it like this in v4.

Best regards,
Bernhard

Quoted 17 lines
Quoted 10 lines

Looking further into the QEMU code, there is even the following comment in sabrelite.c:
/*
* TODO: Ideally we would expose the chip select and spi bus on the
* SoC object using alias properties; then we would not need to
* directly access the underlying spi device object.
*/
To me this comment seems that the authors think in a similar way.

What do you think?

It's difficult for me to know without having much knowledge of ARM devices, but I can see how this might be useful given that SoCs can integrate a lot of different devices into a single address space. Another thing to note is that the comment above was originally written in 2016, and the qdev/QOM APIs (and indeed our knowledge as to how best to use them) have improved considerably since then.

ATB,

Mark.

#19 lore raw

PATCH v3 7/7 hw/isa/piix{3, 4}: Inline and remove create() functions

In reply to Bernhard Beschow

During the previous changesets the create() functions became trivial wrappers around more generic functions. Modernize the code.

---
 hw/i386/pc_piix.c             |  6 +++++-
 hw/isa/piix3.c                | 13 -------------
 hw/isa/piix4.c                | 13 -------------
 hw/mips/malta.c               |  5 ++++-
 include/hw/southbridge/piix.h |  4 ----
 5 files changed, 9 insertions(+), 32 deletions(-)
hw/i386/pc_piix.c +5 -1
index 9d2076a7ca..107efa1ca6 100644
@@ -197,6 +197,9 @@ static void pc_init1(MachineState *machine,
 
     if (pcmc->pci_enabled) {
         PIIX3State *piix3;
+        PCIDevice *pci_dev;
+        const char *type = xen_enabled() ? TYPE_PIIX3_XEN_DEVICE
+                                         : TYPE_PIIX3_DEVICE;
 
         pci_bus = i440fx_init(host_type,
                               pci_type,
@@ -207,7 +210,8 @@ static void pc_init1(MachineState *machine,
                               pci_memory, ram_memory);
         pcms->bus = pci_bus;
 
-        piix3 = piix3_create(pci_bus);
+        pci_dev = pci_create_simple_multifunction(pci_bus, -1, true, type);
+        piix3 = PIIX3_PCI_DEVICE(pci_dev);
         piix3->pic = x86ms->gsi;
         piix3_devfn = piix3->dev.devfn;
         isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0"));
hw/isa/piix3.c +0 -13
index c6ff7795f4..01c376b39a 100644
@@ -399,16 +399,3 @@ static void piix3_register_types(void)
 }
 
 type_init(piix3_register_types)
-
-PIIX3State *piix3_create(PCIBus *pci_bus)
-{
-    PIIX3State *piix3;
-    PCIDevice *pci_dev;
-    const char *type = xen_enabled() ? TYPE_PIIX3_XEN_DEVICE
-                                     : TYPE_PIIX3_DEVICE;
-
-    pci_dev = pci_create_simple_multifunction(pci_bus, -1, true, type);
-    piix3 = PIIX3_PCI_DEVICE(pci_dev);
-
-    return piix3;
-}
hw/isa/piix4.c +0 -13
index 217989227d..677bc2f658 100644
@@ -324,16 +324,3 @@ static void piix4_register_types(void)
 }
 
 type_init(piix4_register_types)
-
-DeviceState *piix4_create(PCIBus *pci_bus)
-{
-    PCIDevice *pci;
-    DeviceState *dev;
-    int devfn = PCI_DEVFN(10, 0);
-
-    pci = pci_create_simple_multifunction(pci_bus, devfn,  true,
-                                          TYPE_PIIX4_PCI_DEVICE);
-    dev = DEVICE(pci);
-
-    return dev;
-}
hw/mips/malta.c +4 -1
index b0fc84ccbb..7afc4bac9a 100644
@@ -1238,6 +1238,7 @@ void mips_malta_init(MachineState *machine)
     int be;
     MaltaState *s;
     DeviceState *dev;
+    PCIDevice *piix4;
 
     s = MIPS_MALTA(qdev_new(TYPE_MIPS_MALTA));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
@@ -1399,7 +1400,9 @@ void mips_malta_init(MachineState *machine)
     empty_slot_init("GT64120", 0, 0x20000000);
 
     /* Southbridge */
-    dev = piix4_create(pci_bus);
+    piix4 = pci_create_simple_multifunction(pci_bus, PCI_DEVFN(10, 0), true,
+                                            TYPE_PIIX4_PCI_DEVICE);
+    dev = DEVICE(piix4);
     isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0"));
     smbus = I2C_BUS(qdev_get_child_bus(dev, "smbus"));
 
include/hw/southbridge/piix.h +0 -4
index e1f5d6d5c8..2693778b23 100644
@@ -68,8 +68,4 @@ DECLARE_INSTANCE_CHECKER(PIIX3State, PIIX3_PCI_DEVICE,
 #define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen"
 #define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
 
-PIIX3State *piix3_create(PCIBus *pci_bus);
-
-DeviceState *piix4_create(PCIBus *pci_bus);
-
 #endif
Signature · 1 line
2.36.1
Reviewed-by on the v3 series
#20 lore raw
In reply to Bernhard Beschow
Quoted 67 lines · Bernhard Beschow

v3:
* Rebase onto 'hw/acpi/piix4: remove legacy piix4_pm_init() function' (Mark) [1]
* Use embedded structs for touched PCI devices (Mark)
* Fix piix4's rtc embedded struct to be initialized by object_initialize_child() (Peter) [2]

Testing done:

1)
make check-avocado for --target-list=x86_64-softmmu,mips-softmmu
Result: All pass.

2)
* qemu-system-x86_64 -M pc -m 2G -cdrom archlinux-2022.05.01-x86_64.iso
* qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0"

In both cases the system booted successfully and it was possible to shut down the system using the poweroff command.

v2:
* Preserve DeviceState * as return value of piix4_create() (Mark)
* Aggregate all type name movements into first commit (Mark)
* Have piix4 southbridge rather than malta board instantiate piix4 pm (me)

Testing done:

1)
make check-avocado for --target-list=x86_64-softmmu,mips-softmmu
Result: All pass.

2)
Modify pci_piix3_realize() to start with

     error_setg(errp, "This is a test");

Then start qemu-system-x86_64 -M pc -m 1G -accel kvm -cpu host -cdrom archlinux-2022.05.01-x86_64.iso.
Result: qemu-system-x86_64 aborts with: "This is a test"

v1:
The piix3 and piix4 southbridge devices still rely on create() functions which are deprecated. This series resolves these functions piece by piece to modernize the code.

Both devices are modified in lockstep where possible to provide more context.

Testing done:
* qemu-system-x86_64 -M pc -m 2G -cdrom archlinux-2022.05.01-x86_64.iso
* qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0"

In both cases the system booted successfully and it was possible to shut down the system using the poweroff command.

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg05686.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg01128.html

Bernhard Beschow (7):
include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names hw/isa/piix4: Use object_initialize_child() for embedded struct hw/isa/piix{3,4}: Move pci_map_irq_fn's near pci_set_irq_fn's hw/isa/piix{3,4}: QOM'ify PCI device creation and wiring hw/isa/piix{3,4}: Factor out ISABus retrieval from create() functions hw/isa/piix4: QOM'ify PIIX4 PM creation
hw/isa/piix{3,4}: Inline and remove create() functions

Quoted 7 lines
  hw/i386/pc_piix.c             |   7 +-
  hw/isa/piix3.c                |  98 ++++++++++++++-------------
  hw/isa/piix4.c                | 120 +++++++++++++++++-----------------
  hw/mips/malta.c               |   7 +-
  include/hw/isa/isa.h          |   2 -
  include/hw/southbridge/piix.h |   6 +-
  6 files changed, 127 insertions(+), 113 deletions(-)

Hi Bernhard,

I've spotted a couple of small things, but once those are fixed this series looks good to me so I'm happy to give a:

Thanks for your patience with these series too: you've done some good work here, however patchsets like this can sometimes take a while to get reviewed because they both i) touch legacy code/APIs and ii) cut across multiple machines and maintainers. I'd really like to get this work, along with your RTC updates, merged soon as it is a great improvement.

One reason that you may not get many reviews is because you've not added the relevant maintainers on To/CC. Due to the large volume of emails on qemu-devel, quite a few maintainers will filter based upon their own email address so it is definitely worth adding them in.

Fortunately you can easily find the relevant maintainer email addresses by running "./scripts/get_maintainer.pl <path-to-git-patch-dir>" on your git format-patch directory. I'd recommend doing this, and also dropping qemu-trivial since I would say these patches are now beyond the trivial threshold.

ATB,

Mark.

#21 lore raw
Quoted 81 lines · Mark Cave-Ayland
Quoted 67 lines · Bernhard Beschow

v3:
* Rebase onto 'hw/acpi/piix4: remove legacy piix4_pm_init() function' (Mark) [1]
* Use embedded structs for touched PCI devices (Mark)
* Fix piix4's rtc embedded struct to be initialized by object_initialize_child() (Peter) [2]

Testing done:

1)
make check-avocado for --target-list=x86_64-softmmu,mips-softmmu
Result: All pass.

2)
* qemu-system-x86_64 -M pc -m 2G -cdrom archlinux-2022.05.01-x86_64.iso
* qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0"

In both cases the system booted successfully and it was possible to shut down the system using the poweroff command.

v2:
* Preserve DeviceState * as return value of piix4_create() (Mark)
* Aggregate all type name movements into first commit (Mark)
* Have piix4 southbridge rather than malta board instantiate piix4 pm (me)

Testing done:

1)
make check-avocado for --target-list=x86_64-softmmu,mips-softmmu
Result: All pass.

2)
Modify pci_piix3_realize() to start with
     error_setg(errp, "This is a test");
Then start qemu-system-x86_64 -M pc -m 1G -accel kvm -cpu host -cdrom archlinux-2022.05.01-x86_64.iso.
Result: qemu-system-x86_64 aborts with: "This is a test"

v1:
The piix3 and piix4 southbridge devices still rely on create() functions which are deprecated. This series resolves these functions piece by piece to modernize the code.

Both devices are modified in lockstep where possible to provide more context.

Testing done:
* qemu-system-x86_64 -M pc -m 2G -cdrom archlinux-2022.05.01-x86_64.iso
* qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0"

In both cases the system booted successfully and it was possible to shut down the system using the poweroff command.

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg05686.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg01128.html

Bernhard Beschow (7):
   include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names hw/isa/piix4: Use object_initialize_child() for embedded struct hw/isa/piix{3,4}: Move pci_map_irq_fn's near pci_set_irq_fn's hw/isa/piix{3,4}: QOM'ify PCI device creation and wiring hw/isa/piix{3,4}: Factor out ISABus retrieval from create() functions hw/isa/piix4: QOM'ify PIIX4 PM creation
   hw/isa/piix{3,4}: Inline and remove create() functions

Quoted 7 lines

  hw/i386/pc_piix.c             |   7 +-
  hw/isa/piix3.c                |  98 ++++++++++++++------------- hw/isa/piix4.c                | 120 +++++++++++++++++----------------- hw/mips/malta.c               |   7 +- include/hw/isa/isa.h          |   2 - include/hw/southbridge/piix.h |   6 +-

  6 files changed, 127 insertions(+), 113 deletions(-)

Hi Bernhard,

I've spotted a couple of small things, but once those are fixed this series looks good to me so I'm happy to give a:

Quoted 7 lines

Thanks for your patience with these series too: you've done some good work here, however patchsets like this can sometimes take a while to get reviewed because they both i) touch legacy code/APIs and ii) cut across multiple machines and maintainers. I'd really like to get this work, along with your RTC updates, merged soon as it is a great improvement.

One reason that you may not get many reviews is because you've not added the relevant maintainers on To/CC. Due to the large volume of emails on qemu-devel, quite a few maintainers will filter based upon their own email address so it is definitely worth adding them in.

Fortunately you can easily find the relevant maintainer email addresses by running "./scripts/get_maintainer.pl <path-to-git-patch-dir>" on your git format-patch directory. I'd recommend doing this, and also dropping qemu-trivial since I would say these patches are now beyond the trivial threshold.

Oh wait - I see now it's just the cover letter which is missing the additional maintainer addresses :) If you could add them into the cover letter for your next revision that would be great, since it gives context for maintainers to help with the review process.

ATB,

Mark.

#22 lore raw
Quoted 124 lines · Mark Cave-Ayland
Quoted 4 lines · Mark Cave-Ayland
Quoted 2 lines · Bernhard Beschow

v3:
* Rebase onto 'hw/acpi/piix4: remove legacy piix4_pm_init() function'

(Mark) [1]

Quoted 4 lines
Quoted 4 lines

* Use embedded structs for touched PCI devices (Mark)
* Fix piix4's rtc embedded struct to be initialized by object_initialize_child() (Peter) [2]

Quoted 8 lines
Quoted 8 lines

Testing done:

1)
make check-avocado for --target-list=x86_64-softmmu,mips-softmmu
Result: All pass.

2)
* `qemu-system-x86_64 -M pc -m 2G -cdrom

archlinux-2022.05.01-x86_64.iso`

Quoted 2 lines
Quoted 2 lines

* `qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1

console=tty0"`

Quoted 2 lines
Quoted 2 lines

In both cases the system booted successfully and it was possible to

shut down

Quoted 7 lines
Quoted 7 lines

the system using the poweroff command.

v2:
* Preserve DeviceState * as return value of piix4_create() (Mark)
* Aggregate all type name movements into first commit (Mark)
* Have piix4 southbridge rather than malta board instantiate piix4 pm

(me)

Quoted 15 lines
Quoted 15 lines

Testing done:

1)
make check-avocado for --target-list=x86_64-softmmu,mips-softmmu
Result: All pass.

2)
Modify pci_piix3_realize() to start with

     error_setg(errp, "This is a test");

Then start qemu-system-x86_64 -M pc -m 1G -accel kvm -cpu host -cdrom archlinux-2022.05.01-x86_64.iso.
Result: qemu-system-x86_64 aborts with: "This is a test"

Quoted 2 lines
Quoted 2 lines

v1:
The piix3 and piix4 southbridge devices still rely on create()

functions which

Quoted 4 lines
Quoted 4 lines

are deprecated. This series resolves these functions piece by piece to modernize the code.

Both devices are modified in lockstep where possible to provide more

context.

Quoted 3 lines
Quoted 3 lines

Testing done:
* `qemu-system-x86_64 -M pc -m 2G -cdrom

archlinux-2022.05.01-x86_64.iso`

Quoted 2 lines
Quoted 2 lines

* `qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1

console=tty0"`

Quoted 2 lines
Quoted 2 lines

In both cases the system booted successfully and it was possible to

shut down

Quoted 7 lines
Quoted 7 lines

the system using the poweroff command.

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg05686.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg01128.html

Bernhard Beschow (7):
include/hw/southbridge/piix: Aggregate all PIIX soughbridge type

names

Quoted 15 lines
Quoted 7 lines

hw/isa/piix4: Use object_initialize_child() for embedded struct hw/isa/piix{3,4}: Move pci_map_irq_fn's near pci_set_irq_fn's hw/isa/piix{3,4}: QOM'ify PCI device creation and wiring hw/isa/piix{3,4}: Factor out ISABus retrieval from create() functions hw/isa/piix4: QOM'ify PIIX4 PM creation
hw/isa/piix{3,4}: Inline and remove create() functions

Quoted 7 lines
  hw/i386/pc_piix.c             |   7 +-
  hw/isa/piix3.c                |  98 ++++++++++++++-------------
  hw/isa/piix4.c                | 120 +++++++++++++++++-----------------
  hw/mips/malta.c               |   7 +-
  include/hw/isa/isa.h          |   2 -
  include/hw/southbridge/piix.h |   6 +-
  6 files changed, 127 insertions(+), 113 deletions(-)
Quoted 3 lines

Hi Bernhard,

I've spotted a couple of small things, but once those are fixed this

series looks

Quoted 5 lines

good to me so I'm happy to give a:

Thanks for your patience with these series too: you've done some good

work here,

Quoted 1 line

however patchsets like this can sometimes take a while to get reviewed

because they

Quoted 1 line

both i) touch legacy code/APIs and ii) cut across multiple machines and

maintainers.

Quoted 1 line

I'd really like to get this work, along with your RTC updates, merged

soon as it is a

Quoted 3 lines

great improvement.

One reason that you may not get many reviews is because you've not added

the relevant

Quoted 1 line

maintainers on To/CC. Due to the large volume of emails on qemu-devel,

quite a few

Quoted 1 line

maintainers will filter based upon their own email address so it is

definitely worth

Quoted 3 lines

adding them in.

Fortunately you can easily find the relevant maintainer email addresses

by running

Quoted 1 line

"./scripts/get_maintainer.pl <path-to-git-patch-dir>" on your git

format-patch

Quoted 1 line

directory. I'd recommend doing this, and also dropping qemu-trivial

since I would say

Quoted 1 line

these patches are now beyond the trivial threshold.

Quoted 8 lines

Oh wait - I see now it's just the cover letter which is missing the additional
maintainer addresses :) If you could add them into the cover letter for your next
revision that would be great, since it gives context for maintainers to help with the
review process.

Hi Mark,

Thanks for your great work you put into reviews and the useful insights! It seems to me that the time it takes for patches to be queued depends on the subsystem - some are faster, some are slower...

I've automated my setup as described in [1]. However, it doesn't seem to work for the cover letter which I'd expect to be sent to the union of all reviewers of all patches. Any idea how to fix this?

Best regards,
Bernhard

[1]
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#cc-the-relevant-maintainer

Quoted 6 lines

ATB,

Mark.

#23 lore raw
Quoted 125 lines · Bernhard Beschow

On Sun, May 29, 2022 at 12:06 PM Mark Cave-Ayland <[email protected] <mailto:[email protected]>> wrote:

On 29/05/2022 10:46, Mark Cave-Ayland wrote:

> On 28/05/2022 20:20, Bernhard Beschow wrote:
>
>> v3:
>> * Rebase onto 'hw/acpi/piix4: remove legacy piix4_pm_init() function' (Mark) [1] >> * Use embedded structs for touched PCI devices (Mark)
>> * Fix piix4's rtc embedded struct to be initialized by
>>    object_initialize_child() (Peter) [2]
>>
>> Testing done:
>>
>> 1)
>> make check-avocado for --target-list=x86_64-softmmu,mips-softmmu >> Result: All pass.
>>
>> 2)
>> * qemu-system-x86_64 -M pc -m 2G -cdrom archlinux-2022.05.01-x86_64.iso >> * qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda >>    debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" >>
>> In both cases the system booted successfully and it was possible to shut down >> the system using the poweroff command.
>>
>>
>> v2:
>> * Preserve DeviceState * as return value of piix4_create() (Mark) >> * Aggregate all type name movements into first commit (Mark)
>> * Have piix4 southbridge rather than malta board instantiate piix4 pm (me) >>
>> Testing done:
>>
>> 1)
>> make check-avocado for --target-list=x86_64-softmmu,mips-softmmu >> Result: All pass.
>>
>> 2)
>> Modify pci_piix3_realize() to start with
>>      error_setg(errp, "This is a test");
>> Then start qemu-system-x86_64 -M pc -m 1G -accel kvm -cpu host -cdrom >> archlinux-2022.05.01-x86_64.iso.
>> Result: qemu-system-x86_64 aborts with: "This is a test"
>>
>>
>> v1:
>> The piix3 and piix4 southbridge devices still rely on create() functions which >> are deprecated. This series resolves these functions piece by piece to >> modernize the code.
>>
>> Both devices are modified in lockstep where possible to provide more context. >>
>> Testing done:
>> * qemu-system-x86_64 -M pc -m 2G -cdrom archlinux-2022.05.01-x86_64.iso >> * qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda >>    debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" >>
>> In both cases the system booted successfully and it was possible to shut down >> the system using the poweroff command.
>>
>> [1] https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg05686.html
<https://lists.gnu.org/archive/html/qemu-devel/2022-05/msg05686.html>
>> [2] https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg01128.html
<https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg01128.html>
>>
>> Bernhard Beschow (7):
>>    include/hw/southbridge/piix: Aggregate all PIIX soughbridge type names >>    hw/isa/piix4: Use object_initialize_child() for embedded struct >>    hw/isa/piix{3,4}: Move pci_map_irq_fn's near pci_set_irq_fn's >>    hw/isa/piix{3,4}: QOM'ify PCI device creation and wiring
>>    hw/isa/piix{3,4}: Factor out ISABus retrieval from create() functions >>    hw/isa/piix4: QOM'ify PIIX4 PM creation
>>    hw/isa/piix{3,4}: Inline and remove create() functions
>>
>>   hw/i386/pc_piix.c             |   7 +-
>>   hw/isa/piix3.c                |  98 ++++++++++++++------------- >>   hw/isa/piix4.c                | 120 +++++++++++++++++----------------- >>   hw/mips/malta.c               |   7 +-
>>   include/hw/isa/isa.h          |   2 -
>>   include/hw/southbridge/piix.h |   6 +-
>>   6 files changed, 127 insertions(+), 113 deletions(-)
>
> Hi Bernhard,
>
> I've spotted a couple of small things, but once those are fixed this series looks > good to me so I'm happy to give a:
>
> Reviewed-by: Mark Cave-Ayland <[email protected]
<mailto:[email protected]>>
>
> Thanks for your patience with these series too: you've done some good work here, > however patchsets like this can sometimes take a while to get reviewed because
they
> both i) touch legacy code/APIs and ii) cut across multiple machines and
maintainers.
> I'd really like to get this work, along with your RTC updates, merged soon as
it is a
> great improvement.
>
> One reason that you may not get many reviews is because you've not added the
relevant
> maintainers on To/CC. Due to the large volume of emails on qemu-devel, quite a
few
> maintainers will filter based upon their own email address so it is definitely
worth
> adding them in.
>
> Fortunately you can easily find the relevant maintainer email addresses by
running
> "./scripts/get_maintainer.pl <http://get_maintainer.pl>
<path-to-git-patch-dir>" on your git format-patch
> directory. I'd recommend doing this, and also dropping qemu-trivial since I
would say
> these patches are now beyond the trivial threshold.

Oh wait - I see now it's just the cover letter which is missing the additional maintainer addresses :)  If you could add them into the cover letter for your next revision that would be great, since it gives context for maintainers to help with the
review process.

Hi Mark,

Quoted 8 lines

Thanks for your great work you put into reviews and the useful insights! It seems to me that the time it takes for patches to be queued depends on the subsystem - some are faster, some are slower...

I've automated my setup as described in [1]. However, it doesn't seem to work for the cover letter which I'd expect to be sent to the union of all reviewers of all patches. Any idea how to fix this?

Best regards,
Bernhard

[1] https://www.qemu.org/docs/master/devel/submitting-a-patch.html#cc-the-relevant-maintainer <https://www.qemu.org/docs/master/devel/submitting-a-patch.html#cc-the-relevant-maintainer>

Good question. I tend to do "git format-patch -o /tmp/foo --cover-letter" to generate the series, fill in the cover letter, and then use "git send-email /tmp/foo" to send out the emails (entering in the results of get_maintainer.pl by hand). I'm not sure why the cover letter isn't being generated correctly in your case I'm afraid.

ATB,

Mark.

#24 lore raw
Quoted 18 lines · Mark Cave-Ayland
Quoted 16 lines · Bernhard Beschow

    Oh wait - I see now it's just the cover letter which is missing the additional maintainer addresses :)  If you could add them into the cover letter for your next revision that would be great, since it gives context for maintainers to help with the
    review process.

Hi Mark,

Thanks for your great work you put into reviews and the useful insights! It seems to me that the time it takes for patches to be queued depends on the subsystem - some are faster, some are slower...

I've automated my setup as described in [1]. However, it doesn't seem to work for the cover letter which I'd expect to be sent to the union of all reviewers of all patches. Any idea how to fix this?

Best regards,
Bernhard

Quoted 6 lines
Quoted 1 line

[1] https://www.qemu.org/docs/master/devel/submitting-a-patch.html#cc-the-relevant-maintainer <https://www.qemu.org/docs/master/devel/submitting-a-patch.html#cc-the-relevant-maintainer>

Good question. I tend to do "git format-patch -o /tmp/foo
--cover-letter" to generate the series, fill in the cover letter, and
then use "git send-email /tmp/foo" to send out the emails (entering in the results of get_maintainer.pl by hand). I'm not sure why the cover letter isn't being generated correctly in your case I'm afraid.

Or try git-publish :) It does a first pass collecting Cc for each patch (calling get_maintainer.pl) then use that set on the cover.

https://github.com/stefanha/git-publish

#25 lore raw

Am 30. Mai 2022 19:45:26 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 22 lines · Mark Cave-Ayland
Quoted 21 lines · Bernhard Beschow
Quoted 18 lines

    Oh wait - I see now it's just the cover letter which is missing the additional maintainer addresses :)  If you could add them into the cover letter for your next revision that would be great, since it gives context for maintainers to help with the
    review process.

Hi Mark,

Thanks for your great work you put into reviews and the useful insights! It seems to me that the time it takes for patches to be queued depends on the subsystem - some are faster, some are slower...

I've automated my setup as described in [1]. However, it doesn't seem to work for the cover letter which I'd expect to be sent to the union of all reviewers of all patches. Any idea how to fix this?

Best regards,
Bernhard

[1] https://www.qemu.org/docs/master/devel/submitting-a-patch.html#cc-the-relevant-maintainer <https://www.qemu.org/docs/master/devel/submitting-a-patch.html#cc-the-relevant-maintainer>

Quoted 6 lines
Quoted 1 line

Good question. I tend to do "git format-patch -o /tmp/foo --cover-letter" to generate the series, fill in the cover letter, and then use "git send-email /tmp/foo" to send out the emails (entering in the results of get_maintainer.pl by hand). I'm not sure why the cover letter isn't being generated correctly in your case I'm afraid.

Or try git-publish :) It does a first pass collecting Cc for each patch (calling get_maintainer.pl) then use that set on the cover.

https://github.com/stefanha/git-publish

Yes, that worked. What an improvement!

Best regards,
Bernhard