qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_


From: Philippe Mathieu-Daudé
Subject: [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link()
Date: Thu, 5 Jan 2023 14:07:06 +0100

A QOM object shouldn't poke at another object internals.

Here the PCI host bridge instantiates its PCI function #0
and sets a reference to itself (so the function can access
the bridge fields).

Pass this reference with object_property_add_const_link(),
since the reference won't change during the object lifetime.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/pci-host/bonito.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index 80ec424f86..d881c85509 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -656,10 +656,17 @@ static void bonito_host_realize(DeviceState *dev, Error 
**errp)
 static void bonito_pci_realize(PCIDevice *dev, Error **errp)
 {
     PCIBonitoState *s = PCI_BONITO(dev);
-    SysBusDevice *sysbus = SYS_BUS_DEVICE(s->pcihost);
-    PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost);
-    BonitoState *bs = BONITO_PCI_HOST_BRIDGE(s->pcihost);
     MemoryRegion *pcimem_alias = g_new(MemoryRegion, 1);
+    SysBusDevice *sysbus;
+    PCIHostState *phb;
+    BonitoState *bs;
+    Object *obj;
+
+    obj = object_property_get_link(OBJECT(dev), "host-bridge", &error_abort);
+    s->pcihost = BONITO_PCI_HOST_BRIDGE(obj);
+    sysbus = SYS_BUS_DEVICE(obj);
+    phb = PCI_HOST_BRIDGE(obj);
+    bs = BONITO_PCI_HOST_BRIDGE(obj);
 
     /*
      * Bonito North Bridge, built on FPGA,
@@ -745,7 +752,6 @@ PCIBus *bonito_init(qemu_irq *pic)
     DeviceState *dev;
     BonitoState *pcihost;
     PCIHostState *phb;
-    PCIBonitoState *s;
     PCIDevice *d;
 
     dev = qdev_new(TYPE_BONITO_PCI_HOST_BRIDGE);
@@ -755,10 +761,9 @@ PCIBus *bonito_init(qemu_irq *pic)
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
     d = pci_new(PCI_DEVFN(0, 0), TYPE_PCI_BONITO);
-    s = PCI_BONITO(d);
-    s->pcihost = pcihost;
-    pcihost->pci_dev = s;
+    object_property_add_const_link(OBJECT(d), "host-bridge", OBJECT(dev));
     pci_realize_and_unref(d, phb->bus, &error_fatal);
+    pcihost->pci_dev = PCI_BONITO(d);
 
     return phb->bus;
 }
-- 
2.38.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]