qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] hw/pci-host/bonito: Housekeeping
@ 2023-01-05 13:07 Philippe Mathieu-Daudé
  2023-01-05 13:07 ` [PATCH 1/8] hw/pci-host/bonito: Convert to 3-phase reset Philippe Mathieu-Daudé
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang

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

-- 
2.38.1



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/8] hw/pci-host/bonito: Convert to 3-phase reset
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
@ 2023-01-05 13:07 ` Philippe Mathieu-Daudé
  2023-01-06 18:43   ` Richard Henderson
  2023-01-05 13:07 ` [PATCH 2/8] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang, Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <philmd@redhat.com>

Convert the TYPE_PCI_BONITO class to use 3-phase reset.

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

diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index a57e81e3a9..b0d09c85d0 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -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;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/8] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
  2023-01-05 13:07 ` [PATCH 1/8] hw/pci-host/bonito: Convert to 3-phase reset Philippe Mathieu-Daudé
@ 2023-01-05 13:07 ` Philippe Mathieu-Daudé
  2023-01-06 18:43   ` Richard Henderson
  2023-01-05 13:07 ` [PATCH 3/8] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang

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

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

diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index b0d09c85d0..a804731f49 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -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);
 }
 
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/8] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
  2023-01-05 13:07 ` [PATCH 1/8] hw/pci-host/bonito: Convert to 3-phase reset Philippe Mathieu-Daudé
  2023-01-05 13:07 ` [PATCH 2/8] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code Philippe Mathieu-Daudé
@ 2023-01-05 13:07 ` Philippe Mathieu-Daudé
  2023-01-06 18:48   ` Richard Henderson
  2023-01-05 13:07 ` [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link() Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang

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

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

diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index a804731f49..80ec424f86 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -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)
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link()
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2023-01-05 13:07 ` [PATCH 3/8] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code Philippe Mathieu-Daudé
@ 2023-01-05 13:07 ` Philippe Mathieu-Daudé
  2023-01-06 18:49   ` Richard Henderson
  2023-01-05 13:07 ` [PATCH 5/8] hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang

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



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 5/8] hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2023-01-05 13:07 ` [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link() Philippe Mathieu-Daudé
@ 2023-01-05 13:07 ` Philippe Mathieu-Daudé
  2023-01-06 18:57   ` Richard Henderson
  2023-01-05 13:07 ` [PATCH 6/8] hw/pci-host/bonito: Sysbus'ify outgoing IRQ Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang

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

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

diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index d881c85509..7722636e9e 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -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;
 }
 
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 6/8] hw/pci-host/bonito: Sysbus'ify outgoing IRQ
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2023-01-05 13:07 ` [PATCH 5/8] hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler Philippe Mathieu-Daudé
@ 2023-01-05 13:07 ` Philippe Mathieu-Daudé
  2023-01-06 19:14   ` Richard Henderson
  2023-01-05 13:07 ` [PATCH 7/8] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang

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

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

diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index 7722636e9e..5f777f95bd 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -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;
 }
 
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 7/8] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2023-01-05 13:07 ` [PATCH 6/8] hw/pci-host/bonito: Sysbus'ify outgoing IRQ Philippe Mathieu-Daudé
@ 2023-01-05 13:07 ` Philippe Mathieu-Daudé
  2023-01-06 19:15   ` Richard Henderson
  2023-01-05 13:07 ` [PATCH 8/8] hw/mips/fuloong2e: Open code bonito_init() Philippe Mathieu-Daudé
  2023-01-13  8:11 ` [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
  8 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 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

diff --git a/MAINTAINERS b/MAINTAINERS
index 7a40d4d865..8274c45f43 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -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
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index 5f777f95bd..df61b051b0 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -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)
 
diff --git a/include/hw/pci-host/bonito.h b/include/hw/pci-host/bonito.h
new file mode 100644
index 0000000000..b8ecf7870a
--- /dev/null
+++ b/include/hw/pci-host/bonito.h
@@ -0,0 +1,18 @@
+/*
+ * QEMU Bonito64 north bridge support
+ *
+ * Copyright (c) 2008 yajin (yajin@vm-kernel.org)
+ * Copyright (c) 2010 Huacai Chen (zltjiangshi@gmail.com)
+ *
+ * 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
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 8/8] hw/mips/fuloong2e: Open code bonito_init()
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2023-01-05 13:07 ` [PATCH 7/8] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header Philippe Mathieu-Daudé
@ 2023-01-05 13:07 ` Philippe Mathieu-Daudé
  2023-01-06 19:16   ` Richard Henderson
  2023-01-13  8:11 ` [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
  8 siblings, 1 reply; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-05 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Huacai Chen, Bernhard Beschow,
	Jiaxun Yang

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/fuloong2e.c    |  6 +++++-
 hw/pci-host/bonito.c   | 15 ---------------
 include/hw/mips/mips.h |  3 ---
 3 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
index 34befa5dd5..f41e19dc3f 100644
--- a/hw/mips/fuloong2e.c
+++ b/hw/mips/fuloong2e.c
@@ -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,
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index df61b051b0..ca5fa2a155 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -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);
diff --git a/include/hw/mips/mips.h b/include/hw/mips/mips.h
index 101799f7d3..4d2db99952 100644
--- a/include/hw/mips/mips.h
+++ b/include/hw/mips/mips.h
@@ -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);
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/8] hw/pci-host/bonito: Convert to 3-phase reset
  2023-01-05 13:07 ` [PATCH 1/8] hw/pci-host/bonito: Convert to 3-phase reset Philippe Mathieu-Daudé
@ 2023-01-06 18:43   ` Richard Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-01-06 18:43 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang,
	Philippe Mathieu-Daudé

On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé<philmd@redhat.com>
> 
> Convert the TYPE_PCI_BONITO class to use 3-phase reset.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/pci-host/bonito.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/8] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code
  2023-01-05 13:07 ` [PATCH 2/8] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code Philippe Mathieu-Daudé
@ 2023-01-06 18:43   ` Richard Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-01-06 18:43 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang

On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> To make it easier to differentiate between the Host Bridge
> object and its PCI function #0, rename bonito_pcihost* as
> bonito_host*.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/pci-host/bonito.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/8] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code
  2023-01-05 13:07 ` [PATCH 3/8] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code Philippe Mathieu-Daudé
@ 2023-01-06 18:48   ` Richard Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-01-06 18:48 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang

On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> To make it easier to differentiate between the Host Bridge
> object and its PCI function #0, rename bonito* as bonito_pci*.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/pci-host/bonito.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link()
  2023-01-05 13:07 ` [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link() Philippe Mathieu-Daudé
@ 2023-01-06 18:49   ` Richard Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-01-06 18:49 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang

On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> 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);

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

     s->pcihost = bs;

Regardless,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/8] hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler
  2023-01-05 13:07 ` [PATCH 5/8] hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler Philippe Mathieu-Daudé
@ 2023-01-06 18:57   ` Richard Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-01-06 18:57 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang

On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> The PCI function #0 is an integral part of the PCI bridge,
> instantiate it internally during the bridge creation.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/pci-host/bonito.c | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
> index d881c85509..7722636e9e 100644
> --- a/hw/pci-host/bonito.c
> +++ b/hw/pci-host/bonito.c
> @@ -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,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 6/8] hw/pci-host/bonito: Sysbus'ify outgoing IRQ
  2023-01-05 13:07 ` [PATCH 6/8] hw/pci-host/bonito: Sysbus'ify outgoing IRQ Philippe Mathieu-Daudé
@ 2023-01-06 19:14   ` Richard Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-01-06 19:14 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang

On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> Since TYPE_BONITO_PCI_HOST_BRIDGE inherits the TYPE_SYSBUS
> interface, use its API the manage the outgoing IRQ.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/pci-host/bonito.c | 15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 7/8] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header
  2023-01-05 13:07 ` [PATCH 7/8] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header Philippe Mathieu-Daudé
@ 2023-01-06 19:15   ` Richard Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-01-06 19:15 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang

On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> Declare the TYPE_BONITO_PCI_HOST_BRIDGE QOM type in a
> header to be able to access it from board code.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   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

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 8/8] hw/mips/fuloong2e: Open code bonito_init()
  2023-01-05 13:07 ` [PATCH 8/8] hw/mips/fuloong2e: Open code bonito_init() Philippe Mathieu-Daudé
@ 2023-01-06 19:16   ` Richard Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Richard Henderson @ 2023-01-06 19:16 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang

On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> This helper is trivial and is called once, directly open-code it.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/mips/fuloong2e.c    |  6 +++++-
>   hw/pci-host/bonito.c   | 15 ---------------
>   include/hw/mips/mips.h |  3 ---
>   3 files changed, 5 insertions(+), 19 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/8] hw/pci-host/bonito: Housekeeping
  2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2023-01-05 13:07 ` [PATCH 8/8] hw/mips/fuloong2e: Open code bonito_init() Philippe Mathieu-Daudé
@ 2023-01-13  8:11 ` Philippe Mathieu-Daudé
  8 siblings, 0 replies; 18+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-01-13  8:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Huacai Chen, Bernhard Beschow, Jiaxun Yang

On 5/1/23 14:07, Philippe Mathieu-Daudé wrote:
> 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.


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2023-01-13  8:12 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
2023-01-05 13:07 ` [PATCH 1/8] hw/pci-host/bonito: Convert to 3-phase reset Philippe Mathieu-Daudé
2023-01-06 18:43   ` Richard Henderson
2023-01-05 13:07 ` [PATCH 2/8] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code Philippe Mathieu-Daudé
2023-01-06 18:43   ` Richard Henderson
2023-01-05 13:07 ` [PATCH 3/8] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code Philippe Mathieu-Daudé
2023-01-06 18:48   ` Richard Henderson
2023-01-05 13:07 ` [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link() Philippe Mathieu-Daudé
2023-01-06 18:49   ` Richard Henderson
2023-01-05 13:07 ` [PATCH 5/8] hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler Philippe Mathieu-Daudé
2023-01-06 18:57   ` Richard Henderson
2023-01-05 13:07 ` [PATCH 6/8] hw/pci-host/bonito: Sysbus'ify outgoing IRQ Philippe Mathieu-Daudé
2023-01-06 19:14   ` Richard Henderson
2023-01-05 13:07 ` [PATCH 7/8] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header Philippe Mathieu-Daudé
2023-01-06 19:15   ` Richard Henderson
2023-01-05 13:07 ` [PATCH 8/8] hw/mips/fuloong2e: Open code bonito_init() Philippe Mathieu-Daudé
2023-01-06 19:16   ` Richard Henderson
2023-01-13  8:11 ` [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).