Skip to contentSkip to conversation

hw/pci-host/bonito: Housekeeping

PATCH In review Philippe Mathieu-Daudé 2 participants 18 messages Jan 5, 2023 – Jan 13, 2023

lore
Share & tools
lore
#0 lore raw

cover hw/pci-host/bonito: Housekeeping

Minor housekeeping while reviewing PCI host bridge models.

- Convert to 3-phase reset
- Set reference using object_property_add_const_link
- Sysbus'ify IRQ
- Open code bonito_init()

Philippe Mathieu-Daudé (8):
hw/pci-host/bonito: Convert to 3-phase reset hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code hw/pci-host/bonito: Set reference using
object_property_add_const_link()
hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler hw/pci-host/bonito: Sysbus'ify outgoing IRQ hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header hw/mips/fuloong2e: Open code bonito_init()

 MAINTAINERS                  |  1 +
 hw/mips/fuloong2e.c          |  6 ++-
 hw/pci-host/bonito.c         | 93 +++++++++++++++---------------------
 include/hw/mips/mips.h       |  3 --
 include/hw/pci-host/bonito.h | 18 +++++++
 5 files changed, 63 insertions(+), 58 deletions(-)
 create mode 100644 include/hw/pci-host/bonito.h
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/8 hw/pci-host/bonito: Convert to 3-phase reset

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

Convert the TYPE_PCI_BONITO class to use 3-phase reset.

---
 hw/pci-host/bonito.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
hw/pci-host/bonito.c +4 -5
index a57e81e3a9..b0d09c85d0 100644
@@ -47,7 +47,6 @@
 #include "hw/mips/mips.h"
 #include "hw/pci/pci_host.h"
 #include "migration/vmstate.h"
-#include "sysemu/reset.h"
 #include "sysemu/runstate.h"
 #include "hw/misc/unimp.h"
 #include "hw/registerfields.h"
@@ -593,9 +592,9 @@ static int pci_bonito_map_irq(PCIDevice *pci_dev, int irq_num)
     }
 }
 
-static void bonito_reset(void *opaque)
+static void bonito_reset_hold(Object *obj)
 {
-    PCIBonitoState *s = opaque;
+    PCIBonitoState *s = PCI_BONITO(obj);
     uint32_t val = 0;
 
     /* set the default value of north bridge registers */
@@ -739,8 +738,6 @@ static void bonito_realize(PCIDevice *dev, Error **errp)
 
     pci_set_byte(dev->config + PCI_MIN_GNT, 0x3c);
     pci_set_byte(dev->config + PCI_MAX_LAT, 0x00);
-
-    qemu_register_reset(bonito_reset, s);
 }
 
 PCIBus *bonito_init(qemu_irq *pic)
@@ -770,7 +767,9 @@ static void bonito_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
+    rc->phases.hold = bonito_reset_hold;
     k->realize = bonito_realize;
     k->vendor_id = 0xdf53;
     k->device_id = 0x00d5;
Signature · 1 line
2.38.1
#3 lore raw

PATCH 2/8 hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code

In reply to Philippe Mathieu-Daudé

To make it easier to differentiate between the Host Bridge object and its PCI function #0, rename bonito_pcihost* as bonito_host*.

---
 hw/pci-host/bonito.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/pci-host/bonito.c +6 -6
index b0d09c85d0..a804731f49 100644
@@ -627,7 +627,7 @@ static const VMStateDescription vmstate_bonito = {
     }
 };
 
-static void bonito_pcihost_realize(DeviceState *dev, Error **errp)
+static void bonito_host_realize(DeviceState *dev, Error **errp)
 {
     PCIHostState *phb = PCI_HOST_BRIDGE(dev);
     BonitoState *bs = BONITO_PCI_HOST_BRIDGE(dev);
@@ -795,23 +795,23 @@ static const TypeInfo bonito_info = {
     },
 };
 
-static void bonito_pcihost_class_init(ObjectClass *klass, void *data)
+static void bonito_host_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    dc->realize = bonito_pcihost_realize;
+    dc->realize = bonito_host_realize;
 }
 
-static const TypeInfo bonito_pcihost_info = {
+static const TypeInfo bonito_host_info = {
     .name          = TYPE_BONITO_PCI_HOST_BRIDGE,
     .parent        = TYPE_PCI_HOST_BRIDGE,
     .instance_size = sizeof(BonitoState),
-    .class_init    = bonito_pcihost_class_init,
+    .class_init    = bonito_host_class_init,
 };
 
 static void bonito_register_types(void)
 {
-    type_register_static(&bonito_pcihost_info);
+    type_register_static(&bonito_host_info);
     type_register_static(&bonito_info);
 }
 
Signature · 1 line
2.38.1
Reviewed-by on v1 2/8
#4 lore raw

Re: [PATCH 2/8] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code

Quoted 8 lines · Philippe Mathieu-Daudé

To make it easier to differentiate between the Host Bridge object and its PCI function #0, rename bonito_pcihost* as bonito_host*.

---
  hw/pci-host/bonito.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)

r~

#5 lore raw

PATCH 3/8 hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code

In reply to Philippe Mathieu-Daudé

To make it easier to differentiate between the Host Bridge object and its PCI function #0, rename bonito* as bonito_pci*.

---
 hw/pci-host/bonito.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
hw/pci-host/bonito.c +8 -8
index a804731f49..80ec424f86 100644
@@ -617,7 +617,7 @@ static void bonito_reset_hold(Object *obj)
     s->regs[BONITO_PCIMAP] = 0x6140;
 }
 
-static const VMStateDescription vmstate_bonito = {
+static const VMStateDescription vmstate_bonito_pci = {
     .name = "Bonito",
     .version_id = 1,
     .minimum_version_id = 1,
@@ -653,7 +653,7 @@ static void bonito_host_realize(DeviceState *dev, Error **errp)
     create_unimplemented_device("pci.io", BONITO_PCIIO_BASE, 1 * MiB);
 }
 
-static void bonito_realize(PCIDevice *dev, Error **errp)
+static void bonito_pci_realize(PCIDevice *dev, Error **errp)
 {
     PCIBonitoState *s = PCI_BONITO(dev);
     SysBusDevice *sysbus = SYS_BUS_DEVICE(s->pcihost);
@@ -763,20 +763,20 @@ PCIBus *bonito_init(qemu_irq *pic)
     return phb->bus;
 }
 
-static void bonito_class_init(ObjectClass *klass, void *data)
+static void bonito_pci_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     rc->phases.hold = bonito_reset_hold;
-    k->realize = bonito_realize;
+    k->realize = bonito_pci_realize;
     k->vendor_id = 0xdf53;
     k->device_id = 0x00d5;
     k->revision = 0x01;
     k->class_id = PCI_CLASS_BRIDGE_HOST;
     dc->desc = "Host bridge";
-    dc->vmsd = &vmstate_bonito;
+    dc->vmsd = &vmstate_bonito_pci;
     /*
      * PCI-facing part of the host bridge, not usable without the
      * host-facing part, which can't be device_add'ed, yet.
@@ -784,11 +784,11 @@ static void bonito_class_init(ObjectClass *klass, void *data)
     dc->user_creatable = false;
 }
 
-static const TypeInfo bonito_info = {
+static const TypeInfo bonito_pci_info = {
     .name          = TYPE_PCI_BONITO,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(PCIBonitoState),
-    .class_init    = bonito_class_init,
+    .class_init    = bonito_pci_class_init,
     .interfaces = (InterfaceInfo[]) {
         { INTERFACE_CONVENTIONAL_PCI_DEVICE },
         { },
@@ -812,7 +812,7 @@ static const TypeInfo bonito_host_info = {
 static void bonito_register_types(void)
 {
     type_register_static(&bonito_host_info);
-    type_register_static(&bonito_info);
+    type_register_static(&bonito_pci_info);
 }
 
 type_init(bonito_register_types)
Signature · 1 line
2.38.1
Reviewed-by on v1 3/8
#6 lore raw

Re: [PATCH 3/8] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code

Quoted 7 lines · Philippe Mathieu-Daudé

To make it easier to differentiate between the Host Bridge object and its PCI function #0, rename bonito* as bonito_pci*.

---
  hw/pci-host/bonito.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)

r~

#7 lore raw

PATCH 4/8 hw/pci-host/bonito: Set reference using object_property_add_const_link()

In reply to Philippe Mathieu-Daudé

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.

---
 hw/pci-host/bonito.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
hw/pci-host/bonito.c +12 -7
index 80ec424f86..d881c85509 100644
@@ -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;
 }
Signature · 1 line
2.38.1
Reviewed-by on v1 4/8
#8 lore raw

Re: [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link()

Quoted 26 lines · Philippe Mathieu-Daudé

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.

---
  hw/pci-host/bonito.c | 19 ++++++++++++-------
  1 file changed, 12 insertions(+), 7 deletions(-)
hw/pci-host/bonito.c +0 -3
index 80ec424f86..d881c85509 100644
@@ -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);

hw/pci-host/bonito.c static void bonito_host_realize(DeviceState *dev, Error **errp) · line 669

Quoted 10 lines
hw/pci-host/bonito.c +10 -0
+    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);

It would be nice to re-order these so that you only perform the dynamic cast once:

    s->pcihost = bs;

Regardless,

r~

#9 lore raw

PATCH 5/8 hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler

In reply to Philippe Mathieu-Daudé

The PCI function #0 is an integral part of the PCI bridge, instantiate it internally during the bridge creation.

---
 hw/pci-host/bonito.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
hw/pci-host/bonito.c +5 -6
index d881c85509..7722636e9e 100644
@@ -651,6 +651,11 @@ static void bonito_host_realize(DeviceState *dev, Error **errp)
     }
 
     create_unimplemented_device("pci.io", BONITO_PCIIO_BASE, 1 * MiB);
+
+    bs->pci_dev = PCI_BONITO(pci_new(PCI_DEVFN(0, 0), TYPE_PCI_BONITO));
+    object_property_add_const_link(OBJECT(bs->pci_dev), "host-bridge",
+                                   OBJECT(bs));
+    pci_realize_and_unref(PCI_DEVICE(bs->pci_dev), phb->bus, &error_fatal);
 }
 
 static void bonito_pci_realize(PCIDevice *dev, Error **errp)
@@ -752,7 +757,6 @@ PCIBus *bonito_init(qemu_irq *pic)
     DeviceState *dev;
     BonitoState *pcihost;
     PCIHostState *phb;
-    PCIDevice *d;
 
     dev = qdev_new(TYPE_BONITO_PCI_HOST_BRIDGE);
     phb = PCI_HOST_BRIDGE(dev);
@@ -760,11 +764,6 @@ PCIBus *bonito_init(qemu_irq *pic)
     pcihost->pic = pic;
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
-    d = pci_new(PCI_DEVFN(0, 0), TYPE_PCI_BONITO);
-    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;
 }
 
Signature · 1 line
2.38.1
Reviewed-by on v1 5/8
#10 lore raw

Re: [PATCH 5/8] hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler

Quoted 13 lines · Philippe Mathieu-Daudé

The PCI function #0 is an integral part of the PCI bridge, instantiate it internally during the bridge creation.

---
  hw/pci-host/bonito.c | 11 +++++------
  1 file changed, 5 insertions(+), 6 deletions(-)
hw/pci-host/bonito.c +0 -0
index d881c85509..7722636e9e 100644

hw/pci-host/bonito.c static void bonito_host_realize(DeviceState *dev, Error **errp) · line 658

Quoted 8 lines
hw/pci-host/bonito.c +5 -0
@@ -651,6 +651,11 @@ static void bonito_host_realize(DeviceState *dev, Error **errp)
      }
 
      create_unimplemented_device("pci.io", BONITO_PCIIO_BASE, 1 * MiB);
+
+    bs->pci_dev = PCI_BONITO(pci_new(PCI_DEVFN(0, 0), TYPE_PCI_BONITO));
+    object_property_add_const_link(OBJECT(bs->pci_dev), "host-bridge",
+                                   OBJECT(bs));
+    pci_realize_and_unref(PCI_DEVICE(bs->pci_dev), phb->bus, &error_fatal);

You can avoid this final dynamic cast by saving the result of pci_new.

Otherwise,

r~

#11 lore raw

PATCH 6/8 hw/pci-host/bonito: Sysbus'ify outgoing IRQ

In reply to Philippe Mathieu-Daudé

Since TYPE_BONITO_PCI_HOST_BRIDGE inherits the TYPE_SYSBUS interface, use its API the manage the outgoing IRQ.

---
 hw/pci-host/bonito.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
hw/pci-host/bonito.c +7 -8
index 7722636e9e..5f777f95bd 100644
@@ -233,7 +233,7 @@ typedef struct PCIBonitoState PCIBonitoState;
 
 struct BonitoState {
     PCIHostState parent_obj;
-    qemu_irq *pic;
+    qemu_irq irq;
     PCIBonitoState *pci_dev;
     MemoryRegion pci_mem;
 };
@@ -556,17 +556,16 @@ static const MemoryRegionOps bonito_spciconf_ops = {
 static void pci_bonito_set_irq(void *opaque, int irq_num, int level)
 {
     BonitoState *s = opaque;
-    qemu_irq *pic = s->pic;
     PCIBonitoState *bonito_state = s->pci_dev;
     int internal_irq = irq_num - BONITO_IRQ_BASE;
 
     if (bonito_state->regs[BONITO_INTEDGE] & (1 << internal_irq)) {
-        qemu_irq_pulse(*pic);
+        qemu_irq_pulse(s->irq);
     } else {   /* level triggered */
         if (bonito_state->regs[BONITO_INTPOL] & (1 << internal_irq)) {
-            qemu_irq_raise(*pic);
+            qemu_irq_raise(s->irq);
         } else {
-            qemu_irq_lower(*pic);
+            qemu_irq_lower(s->irq);
         }
     }
 }
@@ -633,6 +632,7 @@ static void bonito_host_realize(DeviceState *dev, Error **errp)
     BonitoState *bs = BONITO_PCI_HOST_BRIDGE(dev);
     MemoryRegion *pcimem_lo_alias = g_new(MemoryRegion, 3);
 
+    sysbus_init_irq(SYS_BUS_DEVICE(dev), &bs->irq);
     memory_region_init(&bs->pci_mem, OBJECT(dev), "pci.mem", BONITO_PCIHI_SIZE);
     phb->bus = pci_register_root_bus(dev, "pci",
                                      pci_bonito_set_irq, pci_bonito_map_irq,
@@ -755,15 +755,14 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp)
 PCIBus *bonito_init(qemu_irq *pic)
 {
     DeviceState *dev;
-    BonitoState *pcihost;
     PCIHostState *phb;
 
     dev = qdev_new(TYPE_BONITO_PCI_HOST_BRIDGE);
     phb = PCI_HOST_BRIDGE(dev);
-    pcihost = BONITO_PCI_HOST_BRIDGE(dev);
-    pcihost->pic = pic;
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
+    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, *pic);
+
     return phb->bus;
 }
 
Signature · 1 line
2.38.1
#13 lore raw

PATCH 7/8 hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header

In reply to Philippe Mathieu-Daudé

Declare the TYPE_BONITO_PCI_HOST_BRIDGE QOM type in a header to be able to access it from board code.

---
 MAINTAINERS                  |  1 +
 hw/pci-host/bonito.c         |  4 +---
 include/hw/pci-host/bonito.h | 18 ++++++++++++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 include/hw/pci-host/bonito.h
MAINTAINERS +1 -0
index 7a40d4d865..8274c45f43 100644
@@ -1260,6 +1260,7 @@ F: hw/isa/vt82c686.c
 F: hw/pci-host/bonito.c
 F: hw/usb/vt82c686-uhci-pci.c
 F: include/hw/isa/vt82c686.h
+F: include/hw/pci-host/bonito.h
 F: tests/avocado/machine_mips_fuloong2e.py
 
 Loongson-3 virtual platforms
hw/pci-host/bonito.c +1 -3
index 5f777f95bd..df61b051b0 100644
@@ -45,6 +45,7 @@
 #include "hw/pci/pci.h"
 #include "hw/irq.h"
 #include "hw/mips/mips.h"
+#include "hw/pci-host/bonito.h"
 #include "hw/pci/pci_host.h"
 #include "migration/vmstate.h"
 #include "sysemu/runstate.h"
@@ -238,9 +239,6 @@ struct BonitoState {
     MemoryRegion pci_mem;
 };
 
-#define TYPE_BONITO_PCI_HOST_BRIDGE "Bonito-pcihost"
-OBJECT_DECLARE_SIMPLE_TYPE(BonitoState, BONITO_PCI_HOST_BRIDGE)
-
 #define TYPE_PCI_BONITO "Bonito"
 OBJECT_DECLARE_SIMPLE_TYPE(PCIBonitoState, PCI_BONITO)
 
include/hw/pci-host/bonito.h new file +18 -0
new file mode 100644
index 0000000000..b8ecf7870a
@@ -0,0 +1,18 @@
+/*
+ * QEMU Bonito64 north bridge support
+ *
+ * Copyright (c) 2008 yajin ([email protected])
+ * Copyright (c) 2010 Huacai Chen ([email protected])
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_PCI_HOST_BONITO_H
+#define HW_PCI_HOST_BONITO_H
+
+#include "qom/object.h"
+
+#define TYPE_BONITO_PCI_HOST_BRIDGE "Bonito-pcihost"
+OBJECT_DECLARE_SIMPLE_TYPE(BonitoState, BONITO_PCI_HOST_BRIDGE)
+
+#endif
Signature · 1 line
2.38.1
Reviewed-by on v1 7/8
#14 lore raw

Re: [PATCH 7/8] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header

Quoted 10 lines · Philippe Mathieu-Daudé

Declare the TYPE_BONITO_PCI_HOST_BRIDGE QOM type in a header to be able to access it from board code.

---
  MAINTAINERS                  |  1 +
  hw/pci-host/bonito.c         |  4 +---
  include/hw/pci-host/bonito.h | 18 ++++++++++++++++++
  3 files changed, 20 insertions(+), 3 deletions(-)

create mode 100644 include/hw/pci-host/bonito.h

r~

#15 lore raw

PATCH 8/8 hw/mips/fuloong2e: Open code bonito_init()

In reply to Philippe Mathieu-Daudé

This helper is trivial and is called once, directly open-code it.

---
 hw/mips/fuloong2e.c    |  6 +++++-
 hw/pci-host/bonito.c   | 15 ---------------
 include/hw/mips/mips.h |  3 ---
 3 files changed, 5 insertions(+), 19 deletions(-)
hw/mips/fuloong2e.c +5 -1
index 34befa5dd5..f41e19dc3f 100644
@@ -32,6 +32,7 @@
 #include "hw/mips/bootloader.h"
 #include "hw/mips/cpudevs.h"
 #include "hw/pci/pci.h"
+#include "hw/pci-host/bonito.h"
 #include "hw/loader.h"
 #include "hw/ide/pci.h"
 #include "hw/qdev-properties.h"
@@ -292,7 +293,10 @@ static void mips_fuloong2e_init(MachineState *machine)
     cpu_mips_clock_init(cpu);
 
     /* North bridge, Bonito --> IP2 */
-    pci_bus = bonito_init((qemu_irq *)&(env->irq[2]));
+    dev = qdev_new(TYPE_BONITO_PCI_HOST_BRIDGE);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, env->irq[2]);
+    pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci"));
 
     /* South bridge -> IP5 */
     pci_dev = pci_create_simple_multifunction(pci_bus,
hw/pci-host/bonito.c +0 -15
index df61b051b0..ca5fa2a155 100644
@@ -44,7 +44,6 @@
 #include "qemu/error-report.h"
 #include "hw/pci/pci.h"
 #include "hw/irq.h"
-#include "hw/mips/mips.h"
 #include "hw/pci-host/bonito.h"
 #include "hw/pci/pci_host.h"
 #include "migration/vmstate.h"
@@ -750,20 +749,6 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp)
     pci_set_byte(dev->config + PCI_MAX_LAT, 0x00);
 }
 
-PCIBus *bonito_init(qemu_irq *pic)
-{
-    DeviceState *dev;
-    PCIHostState *phb;
-
-    dev = qdev_new(TYPE_BONITO_PCI_HOST_BRIDGE);
-    phb = PCI_HOST_BRIDGE(dev);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
-
-    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, *pic);
-
-    return phb->bus;
-}
-
 static void bonito_pci_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
include/hw/mips/mips.h +0 -3
index 101799f7d3..4d2db99952 100644
@@ -9,9 +9,6 @@
 
 #include "exec/memory.h"
 
-/* bonito.c */
-PCIBus *bonito_init(qemu_irq *pic);
-
 /* rc4030.c */
 typedef struct rc4030DMAState *rc4030_dma;
 void rc4030_dma_read(void *dma, uint8_t *buf, int len);
Signature · 1 line
2.38.1
Reviewed-by on v1 8/8
#16 lore raw

Re: [PATCH 8/8] hw/mips/fuloong2e: Open code bonito_init()

Quoted 8 lines · Philippe Mathieu-Daudé

This helper is trivial and is called once, directly open-code it.

---
  hw/mips/fuloong2e.c    |  6 +++++-
  hw/pci-host/bonito.c   | 15 ---------------
  include/hw/mips/mips.h |  3 ---
  3 files changed, 5 insertions(+), 19 deletions(-)

r~

#17 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Minor housekeeping while reviewing PCI host bridge models.

Philippe Mathieu-Daudé (8):
hw/pci-host/bonito: Convert to 3-phase reset hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code

hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header

Patches 1-3 & 7 queued to mips-next.