[PATCH] hw/pci-bridge: Convert pci-bridge to Resettable interface

Oscar Alejandro Sánchez Lucero posted 1 patch 1 week, 3 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261112-pci-bridge-resettable-v1-1-ed36c7b26fbe@gmail.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>
There is a newer version of this series
hw/pci-bridge/pci_bridge_dev.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
[PATCH] hw/pci-bridge: Convert pci-bridge to Resettable interface
Posted by Oscar Alejandro Sánchez Lucero 1 week, 3 days ago
Replace the deprecated device_class_set_legacy_reset() in pci_bridge_dev.c
with the three-phase ResettableClass interface, chaining the hold phase
to the parent class.

Signed-off-by: Oscar Alejandro Sánchez Lucero <aleszlucero@gmail.com>
---
To: qemu-devel@nongnu.org
To: Michael S. Tsirkin <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
---
 hw/pci-bridge/pci_bridge_dev.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index bc53bcb..4e08852 100644
--- a/hw/pci-bridge/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
@@ -31,11 +31,18 @@
 #include "system/memory.h"
 #include "hw/pci/pci_bus.h"
 #include "hw/core/hotplug.h"
+#include "hw/core/resettable.h"
 #include "qom/object.h"
 
 #define TYPE_PCI_BRIDGE_DEV      "pci-bridge"
 #define TYPE_PCI_BRIDGE_SEAT_DEV "pci-bridge-seat"
-OBJECT_DECLARE_SIMPLE_TYPE(PCIBridgeDev, PCI_BRIDGE_DEV)
+OBJECT_DECLARE_TYPE(PCIBridgeDev, PCIBridgeDevClass, PCI_BRIDGE_DEV)
+
+struct PCIBridgeDevClass {
+    PCIDeviceClass parent_class;
+
+    ResettablePhases parent_phases;
+};
 
 struct PCIBridgeDev {
     /*< private >*/
@@ -158,11 +165,15 @@ static void pci_bridge_dev_write_config(PCIDevice *d,
     }
 }
 
-static void qdev_pci_bridge_dev_reset(DeviceState *qdev)
+static void pci_bridge_dev_reset_hold(Object *obj, ResetType type)
 {
-    PCIDevice *dev = PCI_DEVICE(qdev);
+    PCIDevice *dev = PCI_DEVICE(obj);
+    PCIBridgeDevClass *bdc = PCI_BRIDGE_DEV_GET_CLASS(obj);
 
-    pci_bridge_reset(qdev);
+    if (bdc->parent_phases.hold) {
+        bdc->parent_phases.hold(obj, type);
+    }
+    pci_bridge_reset(DEVICE(obj));
     if (shpc_present(dev)) {
         shpc_reset(dev);
     }
@@ -245,6 +256,8 @@ static void pci_bridge_dev_class_init(ObjectClass *klass, const void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+    PCIBridgeDevClass *bdc = PCI_BRIDGE_DEV_CLASS(klass);
 
     k->realize = pci_bridge_dev_realize;
     k->exit = pci_bridge_dev_exitfn;
@@ -253,7 +266,8 @@ static void pci_bridge_dev_class_init(ObjectClass *klass, const void *data)
     k->device_id = PCI_DEVICE_ID_REDHAT_BRIDGE;
     k->class_id = PCI_CLASS_BRIDGE_PCI;
     dc->desc = "Standard PCI Bridge";
-    device_class_set_legacy_reset(dc, qdev_pci_bridge_dev_reset);
+    resettable_class_set_parent_phases(rc, NULL, pci_bridge_dev_reset_hold,
+                                       NULL, &bdc->parent_phases);
     device_class_set_props(dc, pci_bridge_dev_properties);
     dc->vmsd = &pci_bridge_dev_vmstate;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
@@ -266,6 +280,7 @@ static const TypeInfo pci_bridge_dev_info = {
     .name              = TYPE_PCI_BRIDGE_DEV,
     .parent            = TYPE_PCI_BRIDGE,
     .instance_size     = sizeof(PCIBridgeDev),
+    .class_size        = sizeof(PCIBridgeDevClass),
     .class_init        = pci_bridge_dev_class_init,
     .instance_finalize = pci_bridge_dev_instance_finalize,
     .interfaces = (const InterfaceInfo[]) {

---
base-commit: 29760efaf96bbe5928f8111881eddbf5ac06439e
change-id: 20261112-pci-bridge-resettable-008877a75471

Best regards,
-- 
Oscar Alejandro Sánchez Lucero <aleszlucero@gmail.com>


Re: [PATCH] hw/pci-bridge: Convert pci-bridge to Resettable interface
Posted by Peter Maydell 1 week, 3 days ago
On Thu, 12 Nov 2026 at 13:01, Oscar Alejandro Sánchez Lucero
<aleszlucero@gmail.com> wrote:
>
> Replace the deprecated device_class_set_legacy_reset() in pci_bridge_dev.c
> with the three-phase ResettableClass interface, chaining the hold phase
> to the parent class.
>
> Signed-off-by: Oscar Alejandro Sánchez Lucero <aleszlucero@gmail.com>

> @@ -253,7 +266,8 @@ static void pci_bridge_dev_class_init(ObjectClass *klass, const void *data)
>      k->device_id = PCI_DEVICE_ID_REDHAT_BRIDGE;
>      k->class_id = PCI_CLASS_BRIDGE_PCI;
>      dc->desc = "Standard PCI Bridge";
> -    device_class_set_legacy_reset(dc, qdev_pci_bridge_dev_reset);
> +    resettable_class_set_parent_phases(rc, NULL, pci_bridge_dev_reset_hold,
> +                                       NULL, &bdc->parent_phases);
>      device_class_set_props(dc, pci_bridge_dev_properties);
>      dc->vmsd = &pci_bridge_dev_vmstate;
>      set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
> @@ -266,6 +280,7 @@ static const TypeInfo pci_bridge_dev_info = {
>      .name              = TYPE_PCI_BRIDGE_DEV,
>      .parent            = TYPE_PCI_BRIDGE,
>      .instance_size     = sizeof(PCIBridgeDev),
> +    .class_size        = sizeof(PCIBridgeDevClass),
>      .class_init        = pci_bridge_dev_class_init,
>      .instance_finalize = pci_bridge_dev_instance_finalize,
>      .interfaces = (const InterfaceInfo[]) {

TYPE_PCI_BRIDGE (and its parent TYPE_PCI_DEVICE) don't implement
a reset method. Usually we don't bother setting up the infrastructure
in the child class to chain to the parent class reset unless there
actually is a parent class reset to chain to.

thanks
-- PMM