Skip to contentSkip to conversation

hw/acpi/piix4: remove legacy piix4_pm_init() function

PATCH In review Philippe Mathieu-Daudé 5 participants 16 messages May 30, 2022 – Jun 12, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover hw/acpi/piix4: remove legacy piix4_pm_init() function

From: Philippe Mathieu-Daudé <[email protected]>

This series moves the outstanding logic from piix4_pm_init() into the relevant instance init() and realize() functions, changes the IRQs to use qdev gpios, and then finally removes the now-unused piix4_pm_initfn() function.

v2:
- Addressed Ani & Bernhard review comments

If no further comments I plan to queue this via mips-next end of this week.

Regards,

Phil.

Mark Cave-Ayland (11):
hw/acpi/piix4: move xen_enabled() logic from piix4_pm_init() to

    piix4_pm_realize()
  hw/acpi/piix4: change smm_enabled from int to bool
  hw/acpi/piix4: convert smm_enabled bool to qdev property
  hw/acpi/piix4: move PIIX4PMState into separate piix4.h header
  hw/acpi/piix4: alter piix4_pm_init() to return PIIX4PMState
  hw/acpi/piix4: rename piix4_pm_init() to piix4_pm_initfn()
  hw/acpi/piix4: use qdev gpio to wire up sci_irq
  hw/acpi/piix4: use qdev gpio to wire up smi_irq
  hw/i386/pc_piix: create PIIX4_PM device directly instead of using
    piix4_pm_initfn()
  hw/isa/piix4.c: create PIIX4_PM device directly instead of using
    piix4_pm_initfn()

hw/acpi/piix4: remove unused piix4_pm_initfn() function

 hw/acpi/piix4.c               | 77 ++++++-----------------------------
 hw/i386/acpi-build.c          |  1 +
 hw/i386/pc_piix.c             | 16 +++++---
 hw/isa/piix4.c                | 11 +++--
 include/hw/acpi/piix4.h       | 75 ++++++++++++++++++++++++++++++++++
 include/hw/southbridge/piix.h |  6 ---
 6 files changed, 107 insertions(+), 79 deletions(-)
 create mode 100644 include/hw/acpi/piix4.h
Signature · 1 line
2.36.1
#1 lore raw

PATCH v2 1/11 hw/acpi/piix4: move xen_enabled() logic from piix4_pm_init() to piix4_pm_realize()

From: Mark Cave-Ayland <[email protected]>

This logic can be included as part of piix4_pm_realize() and does not need to be handled externally.

Message-Id: <[email protected]>

---
 hw/acpi/piix4.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/acpi/piix4.c +4 -3
index fe5625d07a..bf20fa139b 100644
@@ -525,6 +525,10 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
     s->machine_ready.notify = piix4_pm_machine_ready;
     qemu_add_machine_init_done_notifier(&s->machine_ready);
 
+    if (xen_enabled()) {
+        s->use_acpi_hotplug_bridge = false;
+    }
+
     piix4_acpi_system_hot_add_init(pci_address_space_io(dev),
                                    pci_get_bus(dev), s);
     qbus_set_hotplug_handler(BUS(pci_get_bus(dev)), OBJECT(s));
@@ -551,9 +555,6 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
     s->irq = sci_irq;
     s->smi_irq = smi_irq;
     s->smm_enabled = smm_enabled;
-    if (xen_enabled()) {
-        s->use_acpi_hotplug_bridge = false;
-    }
 
     pci_realize_and_unref(pci_dev, bus, &error_fatal);
 
Signature · 1 line
2.36.1
#2 lore raw

PATCH v2 2/11 hw/acpi/piix4: change smm_enabled from int to bool

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

This is in preparation for conversion to a qdev property.

Message-Id: <[email protected]>

[PMD: Change simm_enabled from int to bool, suggested by Ani Sinha]
---
 hw/acpi/piix4.c               | 4 ++--
 include/hw/southbridge/piix.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/acpi/piix4.c +2 -2
index bf20fa139b..558c250884 100644
@@ -74,7 +74,7 @@ struct PIIX4PMState {
 
     qemu_irq irq;
     qemu_irq smi_irq;
-    int smm_enabled;
+    bool smm_enabled;
     bool smm_compat;
     Notifier machine_ready;
     Notifier powerdown_notifier;
@@ -538,7 +538,7 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
 
 I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
                       qemu_irq sci_irq, qemu_irq smi_irq,
-                      int smm_enabled, DeviceState **piix4_pm)
+                      bool smm_enabled, DeviceState **piix4_pm)
 {
     PCIDevice *pci_dev;
     DeviceState *dev;
include/hw/southbridge/piix.h +1 -1
index f63f83e5c6..ff8d96ae8c 100644
@@ -19,7 +19,7 @@
 
 I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
                       qemu_irq sci_irq, qemu_irq smi_irq,
-                      int smm_enabled, DeviceState **piix4_pm);
+                      bool smm_enabled, DeviceState **piix4_pm);
 
 /* PIRQRC[A:D]: PIRQx Route Control Registers */
 #define PIIX_PIRQCA 0x60
Signature · 1 line
2.36.1
#3 lore raw

PATCH v2 3/11 hw/acpi/piix4: convert smm_enabled bool to qdev property

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

This allows the smm_enabled value to be set using a standard qdev property instead of being referenced directly in piix4_pm_init().

Message-Id: <[email protected]>

---
 hw/acpi/piix4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/acpi/piix4.c +2 -1
index 558c250884..316e41e1d0 100644
@@ -547,6 +547,7 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
     pci_dev = pci_new(devfn, TYPE_PIIX4_PM);
     dev = DEVICE(pci_dev);
     qdev_prop_set_uint32(dev, "smb_io_base", smb_io_base);
+    qdev_prop_set_bit(dev, "smm-enabled", smm_enabled);
     if (piix4_pm) {
         *piix4_pm = dev;
     }
@@ -554,7 +555,6 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
     s = PIIX4_PM(dev);
     s->irq = sci_irq;
     s->smi_irq = smi_irq;
-    s->smm_enabled = smm_enabled;
 
     pci_realize_and_unref(pci_dev, bus, &error_fatal);
 
@@ -664,6 +664,7 @@ static Property piix4_pm_properties[] = {
     DEFINE_PROP_BOOL("memory-hotplug-support", PIIX4PMState,
                      acpi_memory_hotplug.is_enabled, true),
     DEFINE_PROP_BOOL("smm-compat", PIIX4PMState, smm_compat, false),
+    DEFINE_PROP_BOOL("smm-enabled", PIIX4PMState, smm_enabled, false),
     DEFINE_PROP_BOOL("x-not-migrate-acpi-index", PIIX4PMState,
                       not_migrate_acpi_index, false),
     DEFINE_PROP_END_OF_LIST(),
Signature · 1 line
2.36.1
#4 lore raw

PATCH v2 4/11 hw/acpi/piix4: move PIIX4PMState into separate piix4.h header

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

This allows the QOM types in hw/acpi/piix4.c to be used elsewhere by simply including hw/acpi/piix4.h.

Message-Id: <[email protected]>

---
 hw/acpi/piix4.c               | 43 +-------------------
 hw/i386/acpi-build.c          |  1 +
 include/hw/acpi/piix4.h       | 75 +++++++++++++++++++++++++++++++++++
 include/hw/southbridge/piix.h |  2 -
 4 files changed, 78 insertions(+), 43 deletions(-)
 create mode 100644 include/hw/acpi/piix4.h
hw/acpi/piix4.c +2 -41
index 316e41e1d0..c2177c5093 100644
@@ -28,6 +28,8 @@
 #include "hw/pci/pci.h"
 #include "hw/qdev-properties.h"
 #include "hw/acpi/acpi.h"
+#include "hw/acpi/pcihp.h"
+#include "hw/acpi/piix4.h"
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/xen.h"
@@ -56,47 +58,6 @@ struct pci_status {
     uint32_t down;
 };
 
-struct PIIX4PMState {
-    /*< private >*/
-    PCIDevice parent_obj;
-    /*< public >*/
-
-    MemoryRegion io;
-    uint32_t io_base;
-
-    MemoryRegion io_gpe;
-    ACPIREGS ar;
-
-    APMState apm;
-
-    PMSMBus smb;
-    uint32_t smb_io_base;
-
-    qemu_irq irq;
-    qemu_irq smi_irq;
-    bool smm_enabled;
-    bool smm_compat;
-    Notifier machine_ready;
-    Notifier powerdown_notifier;
-
-    AcpiPciHpState acpi_pci_hotplug;
-    bool use_acpi_hotplug_bridge;
-    bool use_acpi_root_pci_hotplug;
-    bool not_migrate_acpi_index;
-
-    uint8_t disable_s3;
-    uint8_t disable_s4;
-    uint8_t s4_val;
-
-    bool cpu_hotplug_legacy;
-    AcpiCpuHotplug gpe_cpu;
-    CPUHotplugState cpuhp_state;
-
-    MemHotplugState acpi_memory_hotplug;
-};
-
-OBJECT_DECLARE_SIMPLE_TYPE(PIIX4PMState, PIIX4_PM)
-
 static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
                                            PCIBus *bus, PIIX4PMState *s);
 
hw/i386/acpi-build.c +1 -0
index c125939ed6..89ac326d7f 100644
@@ -46,6 +46,7 @@
 #include "hw/acpi/tpm.h"
 #include "hw/acpi/vmgenid.h"
 #include "hw/acpi/erst.h"
+#include "hw/acpi/piix4.h"
 #include "sysemu/tpm_backend.h"
 #include "hw/rtc/mc146818rtc_regs.h"
 #include "migration/vmstate.h"
include/hw/acpi/piix4.h new file +75 -0

75 lines not on this page · raw message

include/hw/southbridge/piix.h +0 -2
index ff8d96ae8c..04cbc3fe30 100644
@@ -15,8 +15,6 @@
 #include "hw/pci/pci.h"
 #include "qom/object.h"
 
-#define TYPE_PIIX4_PM "PIIX4_PM"
-
 I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
                       qemu_irq sci_irq, qemu_irq smi_irq,
                       bool smm_enabled, DeviceState **piix4_pm);
Signature · 1 line
2.36.1
#5 lore raw

PATCH v2 5/11 hw/acpi/piix4: alter piix4_pm_init() to return PIIX4PMState

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

This exposes the PIIX4_PM device to the caller to allow any qdev gpios to be mapped outside of piix4_pm_init().

Message-Id: <[email protected]>

---
 hw/acpi/piix4.c               | 11 ++++-------
 hw/i386/pc_piix.c             | 10 +++++-----
 hw/isa/piix4.c                |  8 +++++---
 include/hw/southbridge/piix.h |  7 ++++---
 4 files changed, 18 insertions(+), 18 deletions(-)
hw/acpi/piix4.c +4 -7
index c2177c5093..c4cfb75020 100644
@@ -497,9 +497,9 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
     piix4_pm_add_properties(s);
 }
 
-I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                      qemu_irq sci_irq, qemu_irq smi_irq,
-                      bool smm_enabled, DeviceState **piix4_pm)
+PIIX4PMState *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
+                            qemu_irq sci_irq, qemu_irq smi_irq,
+                            bool smm_enabled)
 {
     PCIDevice *pci_dev;
     DeviceState *dev;
@@ -509,9 +509,6 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
     dev = DEVICE(pci_dev);
     qdev_prop_set_uint32(dev, "smb_io_base", smb_io_base);
     qdev_prop_set_bit(dev, "smm-enabled", smm_enabled);
-    if (piix4_pm) {
-        *piix4_pm = dev;
-    }
 
     s = PIIX4_PM(dev);
     s->irq = sci_irq;
@@ -519,7 +516,7 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 
     pci_realize_and_unref(pci_dev, bus, &error_fatal);
 
-    return s->smb.smbus;
+    return s;
 }
 
 static uint64_t gpe_readb(void *opaque, hwaddr addr, unsigned width)
hw/i386/pc_piix.c +5 -5
index 578e537b35..891692616b 100644
@@ -281,14 +281,14 @@ static void pc_init1(MachineState *machine,
     }
 
     if (pcmc->pci_enabled && x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) {
-        DeviceState *piix4_pm;
+        PIIX4PMState *piix4_pm;
 
         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
+        piix4_pm = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
+                                 x86ms->gsi[9], smi_irq,
+                                 x86_machine_is_smm_enabled(x86ms));
+        pcms->smbus = I2C_BUS(qdev_get_child_bus(DEVICE(piix4_pm), "i2c"));
         /* TODO: Populate SPD eeprom data.  */
-        pcms->smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
-                                    x86ms->gsi[9], smi_irq,
-                                    x86_machine_is_smm_enabled(x86ms),
-                                    &piix4_pm);
         smbus_eeprom_init(pcms->smbus, 8, NULL, 0);
 
         object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
hw/isa/piix4.c +5 -3
index 8607e0ac36..7d9bedd1bb 100644
@@ -293,6 +293,7 @@ static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
 DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 {
     PIIX4State *s;
+    PIIX4PMState *pms;
     PCIDevice *pci;
     DeviceState *dev;
     int devfn = PCI_DEVFN(10, 0);
@@ -310,9 +311,10 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 
     pci_create_simple(pci_bus, devfn + 2, "piix4-usb-uhci");
     if (smbus) {
-        *smbus = piix4_pm_init(pci_bus, devfn + 3, 0x1100,
-                               qdev_get_gpio_in_named(dev, "isa", 9),
-                               NULL, 0, NULL);
+        pms = piix4_pm_init(pci_bus, devfn + 3, 0x1100,
+                            qdev_get_gpio_in_named(dev, "isa", 9),
+                            NULL, 0);
+        *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pms), "i2c"));
     }
 
     pci_bus_irqs(pci_bus, piix4_set_irq, pci_slot_get_pirq, s, PIIX_NUM_PIRQS);
include/hw/southbridge/piix.h +4 -3
index 04cbc3fe30..a362ec7484 100644
@@ -14,10 +14,11 @@
 
 #include "hw/pci/pci.h"
 #include "qom/object.h"
+#include "hw/acpi/piix4.h"
 
-I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                      qemu_irq sci_irq, qemu_irq smi_irq,
-                      bool smm_enabled, DeviceState **piix4_pm);
+PIIX4PMState *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
+                            qemu_irq sci_irq, qemu_irq smi_irq,
+                            bool smm_enabled);
 
 /* PIRQRC[A:D]: PIRQx Route Control Registers */
 #define PIIX_PIRQCA 0x60
Signature · 1 line
2.36.1
#6 lore raw

PATCH v2 6/11 hw/acpi/piix4: rename piix4_pm_init() to piix4_pm_initfn()

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

When QOMifying a device it is typical to use _init() as the suffix for an instance_init function, however this name is already in use by the legacy piix4_pm_init() wrapper function. Eventually the wrapper function will be removed, but for now rename it to piix4_pm_initfn() to avoid a naming collision.

Message-Id: <[email protected]>

---
 hw/acpi/piix4.c               | 6 +++---
 hw/i386/pc_piix.c             | 6 +++---
 hw/isa/piix4.c                | 6 +++---
 include/hw/southbridge/piix.h | 6 +++---
 4 files changed, 12 insertions(+), 12 deletions(-)
hw/acpi/piix4.c +3 -3
index c4cfb75020..418ec4ee56 100644
@@ -497,9 +497,9 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
     piix4_pm_add_properties(s);
 }
 
-PIIX4PMState *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                            qemu_irq sci_irq, qemu_irq smi_irq,
-                            bool smm_enabled)
+PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
+                              qemu_irq sci_irq, qemu_irq smi_irq,
+                              bool smm_enabled)
 {
     PCIDevice *pci_dev;
     DeviceState *dev;
hw/i386/pc_piix.c +3 -3
index 891692616b..d2ab9f966c 100644
@@ -284,9 +284,9 @@ static void pc_init1(MachineState *machine,
         PIIX4PMState *piix4_pm;
 
         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
-        piix4_pm = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
-                                 x86ms->gsi[9], smi_irq,
-                                 x86_machine_is_smm_enabled(x86ms));
+        piix4_pm = piix4_pm_initfn(pci_bus, piix3_devfn + 3, 0xb100,
+                                   x86ms->gsi[9], smi_irq,
+                                   x86_machine_is_smm_enabled(x86ms));
         pcms->smbus = I2C_BUS(qdev_get_child_bus(DEVICE(piix4_pm), "i2c"));
         /* TODO: Populate SPD eeprom data.  */
         smbus_eeprom_init(pcms->smbus, 8, NULL, 0);
hw/isa/piix4.c +3 -3
index 7d9bedd1bb..33a7015ea3 100644
@@ -311,9 +311,9 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 
     pci_create_simple(pci_bus, devfn + 2, "piix4-usb-uhci");
     if (smbus) {
-        pms = piix4_pm_init(pci_bus, devfn + 3, 0x1100,
-                            qdev_get_gpio_in_named(dev, "isa", 9),
-                            NULL, 0);
+        pms = piix4_pm_initfn(pci_bus, devfn + 3, 0x1100,
+                              qdev_get_gpio_in_named(dev, "isa", 9),
+                              NULL, 0);
         *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pms), "i2c"));
     }
 
include/hw/southbridge/piix.h +3 -3
index a362ec7484..f75a4adf5f 100644
@@ -16,9 +16,9 @@
 #include "qom/object.h"
 #include "hw/acpi/piix4.h"
 
-PIIX4PMState *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                            qemu_irq sci_irq, qemu_irq smi_irq,
-                            bool smm_enabled);
+PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
+                              qemu_irq sci_irq, qemu_irq smi_irq,
+                              bool smm_enabled);
 
 /* PIRQRC[A:D]: PIRQx Route Control Registers */
 #define PIIX_PIRQCA 0x60
Signature · 1 line
2.36.1
#7 lore raw

PATCH v2 7/11 hw/acpi/piix4: use qdev gpio to wire up sci_irq

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Introduce piix4_pm_init() instance init function and use it to initialise the separate qdev gpio for the SCI IRQ.

The sci_irq can now be wired up directly using a qdev gpio instead of having to set the IRQ externally in piix4_pm_initfn().

Message-Id: <[email protected]>

---
 hw/acpi/piix4.c               | 12 +++++++++---
 hw/i386/pc_piix.c             |  4 ++--
 hw/isa/piix4.c                |  6 +++---
 include/hw/southbridge/piix.h |  3 +--
 4 files changed, 15 insertions(+), 10 deletions(-)
hw/acpi/piix4.c +9 -3
index 418ec4ee56..fe5ec0a723 100644
@@ -497,9 +497,15 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
     piix4_pm_add_properties(s);
 }
 
+static void piix4_pm_init(Object *obj)
+{
+    PIIX4PMState *s = PIIX4_PM(obj);
+
+    qdev_init_gpio_out(DEVICE(obj), &s->irq, 1);
+}
+
 PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                              qemu_irq sci_irq, qemu_irq smi_irq,
-                              bool smm_enabled)
+                              qemu_irq smi_irq, bool smm_enabled)
 {
     PCIDevice *pci_dev;
     DeviceState *dev;
@@ -511,7 +517,6 @@ PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
     qdev_prop_set_bit(dev, "smm-enabled", smm_enabled);
 
     s = PIIX4_PM(dev);
-    s->irq = sci_irq;
     s->smi_irq = smi_irq;
 
     pci_realize_and_unref(pci_dev, bus, &error_fatal);
@@ -663,6 +668,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
 static const TypeInfo piix4_pm_info = {
     .name          = TYPE_PIIX4_PM,
     .parent        = TYPE_PCI_DEVICE,
+    .instance_init  = piix4_pm_init,
     .instance_size = sizeof(PIIX4PMState),
     .class_init    = piix4_pm_class_init,
     .interfaces = (InterfaceInfo[]) {
hw/i386/pc_piix.c +2 -2
index d2ab9f966c..0662bf44a9 100644
@@ -284,9 +284,9 @@ static void pc_init1(MachineState *machine,
         PIIX4PMState *piix4_pm;
 
         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
-        piix4_pm = piix4_pm_initfn(pci_bus, piix3_devfn + 3, 0xb100,
-                                   x86ms->gsi[9], smi_irq,
+        piix4_pm = piix4_pm_initfn(pci_bus, piix3_devfn + 3, 0xb100, smi_irq,
                                    x86_machine_is_smm_enabled(x86ms));
+        qdev_connect_gpio_out(DEVICE(piix4_pm), 0, x86ms->gsi[9]);
         pcms->smbus = I2C_BUS(qdev_get_child_bus(DEVICE(piix4_pm), "i2c"));
         /* TODO: Populate SPD eeprom data.  */
         smbus_eeprom_init(pcms->smbus, 8, NULL, 0);
hw/isa/piix4.c +3 -3
index 33a7015ea3..0b6ea22143 100644
@@ -311,9 +311,9 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 
     pci_create_simple(pci_bus, devfn + 2, "piix4-usb-uhci");
     if (smbus) {
-        pms = piix4_pm_initfn(pci_bus, devfn + 3, 0x1100,
-                              qdev_get_gpio_in_named(dev, "isa", 9),
-                              NULL, 0);
+        pms = piix4_pm_initfn(pci_bus, devfn + 3, 0x1100, NULL, 0);
+        qdev_connect_gpio_out(DEVICE(pms), 0,
+                              qdev_get_gpio_in_named(dev, "isa", 9));
         *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pms), "i2c"));
     }
 
include/hw/southbridge/piix.h +1 -2
index f75a4adf5f..105d158f78 100644
@@ -17,8 +17,7 @@
 #include "hw/acpi/piix4.h"
 
 PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                              qemu_irq sci_irq, qemu_irq smi_irq,
-                              bool smm_enabled);
+                              qemu_irq smi_irq, bool smm_enabled);
 
 /* PIRQRC[A:D]: PIRQx Route Control Registers */
 #define PIIX_PIRQCA 0x60
Signature · 1 line
2.36.1
#8 lore raw

PATCH v2 8/11 hw/acpi/piix4: use qdev gpio to wire up smi_irq

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Initialize the SMI IRQ in piix4_pm_init().

The smi_irq can now be wired up directly using a qdev gpio instead of having to set the IRQ externally in piix4_pm_initfn().

Message-Id: <[email protected]>

---
 hw/acpi/piix4.c               | 4 ++--
 hw/i386/pc_piix.c             | 3 ++-
 hw/isa/piix4.c                | 2 +-
 include/hw/southbridge/piix.h | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)
hw/acpi/piix4.c +2 -2
index fe5ec0a723..32033bc9d7 100644
@@ -502,10 +502,11 @@ static void piix4_pm_init(Object *obj)
     PIIX4PMState *s = PIIX4_PM(obj);
 
     qdev_init_gpio_out(DEVICE(obj), &s->irq, 1);
+    qdev_init_gpio_out_named(DEVICE(obj), &s->smi_irq, "smi-irq", 1);
 }
 
 PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                              qemu_irq smi_irq, bool smm_enabled)
+                              bool smm_enabled)
 {
     PCIDevice *pci_dev;
     DeviceState *dev;
@@ -517,7 +518,6 @@ PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
     qdev_prop_set_bit(dev, "smm-enabled", smm_enabled);
 
     s = PIIX4_PM(dev);
-    s->smi_irq = smi_irq;
 
     pci_realize_and_unref(pci_dev, bus, &error_fatal);
 
hw/i386/pc_piix.c +2 -1
index 0662bf44a9..683ec39b80 100644
@@ -284,9 +284,10 @@ static void pc_init1(MachineState *machine,
         PIIX4PMState *piix4_pm;
 
         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
-        piix4_pm = piix4_pm_initfn(pci_bus, piix3_devfn + 3, 0xb100, smi_irq,
+        piix4_pm = piix4_pm_initfn(pci_bus, piix3_devfn + 3, 0xb100,
                                    x86_machine_is_smm_enabled(x86ms));
         qdev_connect_gpio_out(DEVICE(piix4_pm), 0, x86ms->gsi[9]);
+        qdev_connect_gpio_out_named(DEVICE(piix4_pm), "smi-irq", 0, smi_irq);
         pcms->smbus = I2C_BUS(qdev_get_child_bus(DEVICE(piix4_pm), "i2c"));
         /* TODO: Populate SPD eeprom data.  */
         smbus_eeprom_init(pcms->smbus, 8, NULL, 0);
hw/isa/piix4.c +1 -1
index 0b6ea22143..775e15eb20 100644
@@ -311,7 +311,7 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 
     pci_create_simple(pci_bus, devfn + 2, "piix4-usb-uhci");
     if (smbus) {
-        pms = piix4_pm_initfn(pci_bus, devfn + 3, 0x1100, NULL, 0);
+        pms = piix4_pm_initfn(pci_bus, devfn + 3, 0x1100, 0);
         qdev_connect_gpio_out(DEVICE(pms), 0,
                               qdev_get_gpio_in_named(dev, "isa", 9));
         *smbus = I2C_BUS(qdev_get_child_bus(DEVICE(pms), "i2c"));
include/hw/southbridge/piix.h +1 -1
index 105d158f78..b69e0dfb04 100644
@@ -17,7 +17,7 @@
 #include "hw/acpi/piix4.h"
 
 PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                              qemu_irq smi_irq, bool smm_enabled);
+                              bool smm_enabled);
 
 /* PIRQRC[A:D]: PIRQx Route Control Registers */
 #define PIIX_PIRQCA 0x60
Signature · 1 line
2.36.1
#9 lore raw

PATCH v2 9/11 hw/i386/pc_piix: create PIIX4_PM device directly instead of using piix4_pm_initfn()

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Now that all external logic has been removed from piix4_pm_initfn() the PIIX4_PM device can be instantiated directly.

Message-Id: <[email protected]>

---
 hw/i386/pc_piix.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +8 -3
index 683ec39b80..d6668b7c06 100644
@@ -47,6 +47,7 @@
 #include "hw/xen/xen-x86.h"
 #include "exec/memory.h"
 #include "hw/acpi/acpi.h"
+#include "hw/acpi/piix4.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "sysemu/xen.h"
@@ -281,11 +282,15 @@ static void pc_init1(MachineState *machine,
     }
 
     if (pcmc->pci_enabled && x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) {
-        PIIX4PMState *piix4_pm;
+        PCIDevice *piix4_pm;
 
         smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
-        piix4_pm = piix4_pm_initfn(pci_bus, piix3_devfn + 3, 0xb100,
-                                   x86_machine_is_smm_enabled(x86ms));
+        piix4_pm = pci_new(piix3_devfn + 3, TYPE_PIIX4_PM);
+        qdev_prop_set_uint32(DEVICE(piix4_pm), "smb_io_base", 0xb100);
+        qdev_prop_set_bit(DEVICE(piix4_pm), "smm-enabled",
+                          x86_machine_is_smm_enabled(x86ms));
+        pci_realize_and_unref(piix4_pm, pci_bus, &error_fatal);
+
         qdev_connect_gpio_out(DEVICE(piix4_pm), 0, x86ms->gsi[9]);
         qdev_connect_gpio_out_named(DEVICE(piix4_pm), "smi-irq", 0, smi_irq);
         pcms->smbus = I2C_BUS(qdev_get_child_bus(DEVICE(piix4_pm), "i2c"));
Signature · 1 line
2.36.1
#10 lore raw

PATCH v2 10/11 hw/isa/piix4.c: create PIIX4_PM device directly instead of using piix4_pm_initfn()

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Now that all external logic has been removed from piix4_pm_initfn() the PIIX4_PM device can be instantiated directly.

Message-Id: <[email protected]>

---
 hw/isa/piix4.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
hw/isa/piix4.c +7 -4
index 775e15eb20..9a6d981037 100644
@@ -34,6 +34,7 @@
 #include "hw/timer/i8254.h"
 #include "hw/rtc/mc146818rtc.h"
 #include "hw/ide/pci.h"
+#include "hw/acpi/piix4.h"
 #include "migration/vmstate.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
@@ -293,7 +294,6 @@ static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
 DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 {
     PIIX4State *s;
-    PIIX4PMState *pms;
     PCIDevice *pci;
     DeviceState *dev;
     int devfn = PCI_DEVFN(10, 0);
@@ -311,10 +311,13 @@ DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus)
 
     pci_create_simple(pci_bus, devfn + 2, "piix4-usb-uhci");
     if (smbus) {
-        pms = piix4_pm_initfn(pci_bus, devfn + 3, 0x1100, 0);
-        qdev_connect_gpio_out(DEVICE(pms), 0,
+        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(pms), "i2c"));
+        *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);
Signature · 1 line
2.36.1
#11 lore raw

PATCH v2 11/11 hw/acpi/piix4: remove unused piix4_pm_initfn() function

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

This function is now unused and so can be completely removed.

Message-Id: <[email protected]>

---
 hw/acpi/piix4.c               | 19 -------------------
 include/hw/southbridge/piix.h |  4 ----
 2 files changed, 23 deletions(-)
hw/acpi/piix4.c +0 -19
index 32033bc9d7..0a81f1ad93 100644
@@ -505,25 +505,6 @@ static void piix4_pm_init(Object *obj)
     qdev_init_gpio_out_named(DEVICE(obj), &s->smi_irq, "smi-irq", 1);
 }
 
-PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                              bool smm_enabled)
-{
-    PCIDevice *pci_dev;
-    DeviceState *dev;
-    PIIX4PMState *s;
-
-    pci_dev = pci_new(devfn, TYPE_PIIX4_PM);
-    dev = DEVICE(pci_dev);
-    qdev_prop_set_uint32(dev, "smb_io_base", smb_io_base);
-    qdev_prop_set_bit(dev, "smm-enabled", smm_enabled);
-
-    s = PIIX4_PM(dev);
-
-    pci_realize_and_unref(pci_dev, bus, &error_fatal);
-
-    return s;
-}
-
 static uint64_t gpe_readb(void *opaque, hwaddr addr, unsigned width)
 {
     PIIX4PMState *s = opaque;
include/hw/southbridge/piix.h +0 -4
index b69e0dfb04..976b4da582 100644
@@ -14,10 +14,6 @@
 
 #include "hw/pci/pci.h"
 #include "qom/object.h"
-#include "hw/acpi/piix4.h"
-
-PIIX4PMState *piix4_pm_initfn(PCIBus *bus, int devfn, uint32_t smb_io_base,
-                              bool smm_enabled);
 
 /* PIRQRC[A:D]: PIRQx Route Control Registers */
 #define PIIX_PIRQCA 0x60
Signature · 1 line
2.36.1
Reviewed-by on the v2 series
#12 lore raw
In reply to Philippe Mathieu-Daudé

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

Quoted 9 lines

From: Philippe Mathieu-Daudé <[email protected]>

This series moves the outstanding logic from piix4_pm_init() into the relevant instance init() and realize() functions, changes the IRQs to use qdev gpios, and then finally removes the now-unused piix4_pm_initfn() function.

v2:
- Addressed Ani & Bernhard review comments

Patch 4 still introduces the redundant include in acpi/piix4.c, and perhaps all includes already included in the new piix4.h could still be removed alrogether [1]. Anyway:

[1] https://lists.nongnu.org/archive/html/qemu-devel/2022-05/msg05756.html

Quoted 33 lines

If no further comments I plan to queue this via mips-next end of this week.

Regards,

Phil.

Mark Cave-Ayland (11):
hw/acpi/piix4: move xen_enabled() logic from piix4_pm_init() to
piix4_pm_realize()
hw/acpi/piix4: change smm_enabled from int to bool hw/acpi/piix4: convert smm_enabled bool to qdev property hw/acpi/piix4: move PIIX4PMState into separate piix4.h header hw/acpi/piix4: alter piix4_pm_init() to return PIIX4PMState hw/acpi/piix4: rename piix4_pm_init() to piix4_pm_initfn() hw/acpi/piix4: use qdev gpio to wire up sci_irq hw/acpi/piix4: use qdev gpio to wire up smi_irq hw/i386/pc_piix: create PIIX4_PM device directly instead of using
piix4_pm_initfn()
hw/isa/piix4.c: create PIIX4_PM device directly instead of using
piix4_pm_initfn()
hw/acpi/piix4: remove unused piix4_pm_initfn() function

hw/acpi/piix4.c               | 77 ++++++-----------------------------
hw/i386/acpi-build.c          |  1 +
hw/i386/pc_piix.c             | 16 +++++---
hw/isa/piix4.c                | 11 +++--
include/hw/acpi/piix4.h       | 75 ++++++++++++++++++++++++++++++++++
include/hw/southbridge/piix.h |  6 ---
6 files changed, 107 insertions(+), 79 deletions(-)

create mode 100644 include/hw/acpi/piix4.h

#13 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 33 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

This series moves the outstanding logic from piix4_pm_init() into the relevant instance init() and realize() functions, changes the IRQs to use qdev gpios, and then finally removes the now-unused piix4_pm_initfn() function.

v2:
- Addressed Ani & Bernhard review comments

If no further comments I plan to queue this via mips-next end of this week.

Regards,

Phil.

Mark Cave-Ayland (11):
hw/acpi/piix4: move xen_enabled() logic from piix4_pm_init() to

     piix4_pm_realize()
   hw/acpi/piix4: change smm_enabled from int to bool
   hw/acpi/piix4: convert smm_enabled bool to qdev property
   hw/acpi/piix4: move PIIX4PMState into separate piix4.h header
   hw/acpi/piix4: alter piix4_pm_init() to return PIIX4PMState
   hw/acpi/piix4: rename piix4_pm_init() to piix4_pm_initfn()
   hw/acpi/piix4: use qdev gpio to wire up sci_irq
   hw/acpi/piix4: use qdev gpio to wire up smi_irq
   hw/i386/pc_piix: create PIIX4_PM device directly instead of using
     piix4_pm_initfn()
   hw/isa/piix4.c: create PIIX4_PM device directly instead of using
     piix4_pm_initfn()

hw/acpi/piix4: remove unused piix4_pm_initfn() function

Quoted 8 lines
  hw/acpi/piix4.c               | 77 ++++++-----------------------------
  hw/i386/acpi-build.c          |  1 +
  hw/i386/pc_piix.c             | 16 +++++---
  hw/isa/piix4.c                | 11 +++--
  include/hw/acpi/piix4.h       | 75 ++++++++++++++++++++++++++++++++++
  include/hw/southbridge/piix.h |  6 ---
  6 files changed, 107 insertions(+), 79 deletions(-)

create mode 100644 include/hw/acpi/piix4.h

Hi Phil,

I see that you haven't yet sent over the PR for this, so I wondering if it makes sense to add Bernhard's other series to mips-next first since they are good cleanups:

https://patchew.org/QEMU/[email protected]/ (QOMify Sbridge)

https://patchew.org/QEMU/[email protected]/  (RTC)
https://patchew.org/QEMU/[email protected]/   (Random cleanups)
https://patchew.org/QEMU/[email protected]/  (Werror fix)

Alternatively if you are busy, please let me know if you are happy for me to send a PR with Bernhard's fixes via qemu-sparc on your behalf.

ATB,

Mark.

#14 lore raw
Quoted 44 lines · Mark Cave-Ayland
Quoted 33 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

This series moves the outstanding logic from piix4_pm_init() into the relevant instance init() and realize() functions, changes the IRQs to use qdev gpios, and then finally removes the now-unused piix4_pm_initfn() function.

v2:
- Addressed Ani & Bernhard review comments

If no further comments I plan to queue this via mips-next end of this week.

Regards,

Phil.

Mark Cave-Ayland (11):
   hw/acpi/piix4: move xen_enabled() logic from piix4_pm_init() to piix4_pm_realize()
   hw/acpi/piix4: change smm_enabled from int to bool hw/acpi/piix4: convert smm_enabled bool to qdev property hw/acpi/piix4: move PIIX4PMState into separate piix4.h header hw/acpi/piix4: alter piix4_pm_init() to return PIIX4PMState hw/acpi/piix4: rename piix4_pm_init() to piix4_pm_initfn() hw/acpi/piix4: use qdev gpio to wire up sci_irq hw/acpi/piix4: use qdev gpio to wire up smi_irq hw/i386/pc_piix: create PIIX4_PM device directly instead of using piix4_pm_initfn()
   hw/isa/piix4.c: create PIIX4_PM device directly instead of using piix4_pm_initfn()
   hw/acpi/piix4: remove unused piix4_pm_initfn() function

Quoted 8 lines

  hw/acpi/piix4.c               | 77 ++++++----------------------------- hw/i386/acpi-build.c          |  1 +
  hw/i386/pc_piix.c             | 16 +++++---
  hw/isa/piix4.c                | 11 +++-- include/hw/acpi/piix4.h       | 75 ++++++++++++++++++++++++++++++++++ include/hw/southbridge/piix.h |  6 ---

  6 files changed, 107 insertions(+), 79 deletions(-)

  create mode 100644 include/hw/acpi/piix4.h

Quoted 8 lines

Hi Phil,

I see that you haven't yet sent over the PR for this, so I wondering if it makes sense to add Bernhard's other series to mips-next first since they are good cleanups:

https://patchew.org/QEMU/[email protected]/ (QOMify Sbridge)
https://patchew.org/QEMU/[email protected]/  (RTC)
https://patchew.org/QEMU/[email protected]/ (Random cleanups)
https://patchew.org/QEMU/[email protected]/ (Werror fix)

Thanks for the head up :) All now queued via mips-next!

Quoted 6 lines

Alternatively if you are busy, please let me know if you are happy for me to send a PR with Bernhard's fixes via qemu-sparc on your behalf.

ATB,

Mark.

Acked-by on the v2 series
#15 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

This series moves the outstanding logic from piix4_pm_init() into the relevant instance init() and realize() functions, changes the IRQs to use qdev gpios, and then finally removes the now-unused piix4_pm_initfn() function.

Looks ok

Quoted 37 lines

v2:
- Addressed Ani & Bernhard review comments

If no further comments I plan to queue this via mips-next end of this week.

Regards,

Phil.

Mark Cave-Ayland (11):
hw/acpi/piix4: move xen_enabled() logic from piix4_pm_init() to

    piix4_pm_realize()
  hw/acpi/piix4: change smm_enabled from int to bool
  hw/acpi/piix4: convert smm_enabled bool to qdev property
  hw/acpi/piix4: move PIIX4PMState into separate piix4.h header
  hw/acpi/piix4: alter piix4_pm_init() to return PIIX4PMState
  hw/acpi/piix4: rename piix4_pm_init() to piix4_pm_initfn()
  hw/acpi/piix4: use qdev gpio to wire up sci_irq
  hw/acpi/piix4: use qdev gpio to wire up smi_irq
  hw/i386/pc_piix: create PIIX4_PM device directly instead of using
    piix4_pm_initfn()
  hw/isa/piix4.c: create PIIX4_PM device directly instead of using
    piix4_pm_initfn()

hw/acpi/piix4: remove unused piix4_pm_initfn() function

 hw/acpi/piix4.c               | 77 ++++++-----------------------------
 hw/i386/acpi-build.c          |  1 +
 hw/i386/pc_piix.c             | 16 +++++---
 hw/isa/piix4.c                | 11 +++--
 include/hw/acpi/piix4.h       | 75 ++++++++++++++++++++++++++++++++++
 include/hw/southbridge/piix.h |  6 ---
 6 files changed, 107 insertions(+), 79 deletions(-)
 create mode 100644 include/hw/acpi/piix4.h
Signature · 1 line
2.36.1