qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH prep for-1.4? v2 0/2] prep_pci: Prepare for QOM realize
@ 2013-01-16 15:11 Andreas Färber
  2013-01-16 15:11 ` [Qemu-devel] [PATCH prep for-1.4? v2 1/2] prep_pci: Create PCIBus and PCIDevice in-place Andreas Färber
  2013-01-16 15:11 ` [Qemu-devel] [PATCH prep for-1.4? v2 2/2] prep_pci: Convert to QOM realizefn Andreas Färber
  0 siblings, 2 replies; 3+ messages in thread
From: Andreas Färber @ 2013-01-16 15:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Markus Armbruster, Alexander Graf, Andreas Färber,
	Hervé Poussineau, anthony, pbonzini

From: Andreas Färber <andreas.faerber@web.de>

Hello Anthony and Paolo,

Here's a respin of the patch that prompted the big PCI host bridge refactoring.
It embeds PCIBus and PCIDevice into the host bridge state QOM-style.
Question: Is the use of object_unref() correct and future-proof now?

I'm also adding a second patch even more as an example of what is possible with
QOM types and now QOM realize: New SysBusDevices (e.g., IDE refactoring) can get
a realizefn straight away!

Regards,
Andreas

v1 -> v2:
* Rebased onto PCI header reorganization (pci_internal.h -> pci/pci_bus.h).
* Replaced privatized object_finalize() with object_unref().
* Added patch converting initfn to realizefn.

Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Alexander Graf <agraf@suse.de>
Cc: Hervé Poussineau <hpoussin@reactos.org>

Andreas Färber (2):
  prep_pci: Create PCIBus and PCIDevice in-place
  prep_pci: Convert to QOM realizefn

 hw/prep_pci.c |   65 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 Datei geändert, 49 Zeilen hinzugefügt(+), 16 Zeilen entfernt(-)

-- 
1.7.10.4

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

* [Qemu-devel] [PATCH prep for-1.4? v2 1/2] prep_pci: Create PCIBus and PCIDevice in-place
  2013-01-16 15:11 [Qemu-devel] [PATCH prep for-1.4? v2 0/2] prep_pci: Prepare for QOM realize Andreas Färber
@ 2013-01-16 15:11 ` Andreas Färber
  2013-01-16 15:11 ` [Qemu-devel] [PATCH prep for-1.4? v2 2/2] prep_pci: Convert to QOM realizefn Andreas Färber
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2013-01-16 15:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, Andreas Färber, open list:PReP, anthony

From: Andreas Färber <andreas.faerber@web.de>

Prepares for QOM realizefn by removing object creation from qdev initfn.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 hw/prep_pci.c |   59 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 Datei geändert, 46 Zeilen hinzugefügt(+), 13 Zeilen entfernt(-)

diff --git a/hw/prep_pci.c b/hw/prep_pci.c
index 212a2ac..10196b6 100644
--- a/hw/prep_pci.c
+++ b/hw/prep_pci.c
@@ -2,6 +2,7 @@
  * QEMU PREP PCI host
  *
  * Copyright (c) 2006 Fabrice Bellard
+ * Copyright (c) 2011-2013 Andreas Färber
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -24,12 +25,21 @@
 
 #include "hw.h"
 #include "pci/pci.h"
+#include "pci/pci_bus.h"
 #include "pci/pci_host.h"
 #include "pc.h"
 #include "exec/address-spaces.h"
 
+#define TYPE_RAVEN_PCI_DEVICE "raven"
 #define TYPE_RAVEN_PCI_HOST_BRIDGE "raven-pcihost"
 
+#define RAVEN_PCI_DEVICE(obj) \
+    OBJECT_CHECK(RavenPCIState, (obj), TYPE_RAVEN_PCI_DEVICE)
+
+typedef struct RavenPCIState {
+    PCIDevice dev;
+} RavenPCIState;
+
 #define RAVEN_PCI_HOST_BRIDGE(obj) \
     OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE)
 
@@ -38,12 +48,10 @@ typedef struct PRePPCIState {
 
     MemoryRegion intack;
     qemu_irq irq[4];
+    PCIBus pci_bus;
+    RavenPCIState pci_dev;
 } PREPPCIState;
 
-typedef struct RavenPCIState {
-    PCIDevice dev;
-} RavenPCIState;
-
 static inline uint32_t PPC_PCIIO_config(hwaddr addr)
 {
     int i;
@@ -108,18 +116,13 @@ static int raven_pcihost_init(SysBusDevice *dev)
     PCIHostState *h = PCI_HOST_BRIDGE(dev);
     PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(dev);
     MemoryRegion *address_space_mem = get_system_memory();
-    MemoryRegion *address_space_io = get_system_io();
-    PCIBus *bus;
     int i;
 
     for (i = 0; i < 4; i++) {
         sysbus_init_irq(dev, &s->irq[i]);
     }
 
-    bus = pci_register_bus(DEVICE(dev), NULL,
-                           prep_set_irq, prep_map_irq, s->irq,
-                           address_space_mem, address_space_io, 0, 4);
-    h->bus = bus;
+    pci_bus_irqs(&s->pci_bus, prep_set_irq, prep_map_irq, s->irq, 4);
 
     memory_region_init_io(&h->conf_mem, &pci_host_conf_be_ops, s,
                           "pci-conf-idx", 1);
@@ -136,9 +139,37 @@ static int raven_pcihost_init(SysBusDevice *dev)
 
     memory_region_init_io(&s->intack, &PPC_intack_ops, s, "pci-intack", 1);
     memory_region_add_subregion(address_space_mem, 0xbffffff0, &s->intack);
-    pci_create_simple(bus, 0, "raven");
 
-    return 0;
+    /* TODO Remove once realize propagates to child devices. */
+    return qdev_init(DEVICE(&s->pci_dev));
+}
+
+static void raven_pcihost_initfn(Object *obj)
+{
+    PCIHostState *h = PCI_HOST_BRIDGE(obj);
+    PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(obj);
+    MemoryRegion *address_space_mem = get_system_memory();
+    MemoryRegion *address_space_io = get_system_io();
+    DeviceState *pci_dev;
+
+    pci_bus_new_inplace(&s->pci_bus, DEVICE(obj), NULL,
+                        address_space_mem, address_space_io, 0);
+    h->bus = &s->pci_bus;
+
+    object_initialize(&s->pci_dev, TYPE_RAVEN_PCI_DEVICE);
+    pci_dev = DEVICE(&s->pci_dev);
+    qdev_set_parent_bus(pci_dev, BUS(&s->pci_bus));
+    object_property_set_int(OBJECT(&s->pci_dev), PCI_DEVFN(0, 0), "addr",
+                            NULL);
+    qdev_prop_set_bit(pci_dev, "multifunction", false);
+}
+
+static void raven_pcihost_finalizefn(Object *obj)
+{
+    PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(obj);
+
+    object_unref(OBJECT(&s->pci_bus));
+    object_unref(OBJECT(&s->pci_dev));
 }
 
 static int raven_init(PCIDevice *d)
@@ -176,7 +207,7 @@ static void raven_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo raven_info = {
-    .name = "raven",
+    .name = TYPE_RAVEN_PCI_DEVICE,
     .parent = TYPE_PCI_DEVICE,
     .instance_size = sizeof(RavenPCIState),
     .class_init = raven_class_init,
@@ -196,6 +227,8 @@ static const TypeInfo raven_pcihost_info = {
     .name = TYPE_RAVEN_PCI_HOST_BRIDGE,
     .parent = TYPE_PCI_HOST_BRIDGE,
     .instance_size = sizeof(PREPPCIState),
+    .instance_init = raven_pcihost_initfn,
+    .instance_finalize = raven_pcihost_finalizefn,
     .class_init = raven_pcihost_class_init,
 };
 
-- 
1.7.10.4

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

* [Qemu-devel] [PATCH prep for-1.4? v2 2/2] prep_pci: Convert to QOM realizefn
  2013-01-16 15:11 [Qemu-devel] [PATCH prep for-1.4? v2 0/2] prep_pci: Prepare for QOM realize Andreas Färber
  2013-01-16 15:11 ` [Qemu-devel] [PATCH prep for-1.4? v2 1/2] prep_pci: Create PCIBus and PCIDevice in-place Andreas Färber
@ 2013-01-16 15:11 ` Andreas Färber
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2013-01-16 15:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, Andreas Färber, open list:PReP, anthony

From: Andreas Färber <andreas.faerber@web.de>

SysBusDeviceClass' initfn merely calls SysBusDeviceClass::init, so we
can already hook up our own realizefn overwriting this behavior.

A symmetric unrealizefn is not necessary, knowing that the child's
unrealizefn is still no-op, too. Avoids ripping it out again when
recursive realization at DeviceState-level is implemented.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 hw/prep_pci.c |    8 ++++----
 1 Datei geändert, 4 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

diff --git a/hw/prep_pci.c b/hw/prep_pci.c
index 10196b6..a2bd1c5 100644
--- a/hw/prep_pci.c
+++ b/hw/prep_pci.c
@@ -111,8 +111,9 @@ static void prep_set_irq(void *opaque, int irq_num, int level)
     qemu_set_irq(pic[irq_num] , level);
 }
 
-static int raven_pcihost_init(SysBusDevice *dev)
+static void raven_pcihost_realizefn(DeviceState *d, Error **errp)
 {
+    SysBusDevice *dev = SYS_BUS_DEVICE(d);
     PCIHostState *h = PCI_HOST_BRIDGE(dev);
     PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(dev);
     MemoryRegion *address_space_mem = get_system_memory();
@@ -141,7 +142,7 @@ static int raven_pcihost_init(SysBusDevice *dev)
     memory_region_add_subregion(address_space_mem, 0xbffffff0, &s->intack);
 
     /* TODO Remove once realize propagates to child devices. */
-    return qdev_init(DEVICE(&s->pci_dev));
+    object_property_set_bool(OBJECT(&s->pci_dev), true, "realized", errp);
 }
 
 static void raven_pcihost_initfn(Object *obj)
@@ -215,10 +216,9 @@ static const TypeInfo raven_info = {
 
 static void raven_pcihost_class_init(ObjectClass *klass, void *data)
 {
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = raven_pcihost_init;
+    dc->realize = raven_pcihost_realizefn;
     dc->fw_name = "pci";
     dc->no_user = 1;
 }
-- 
1.7.10.4

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

end of thread, other threads:[~2013-01-16 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-16 15:11 [Qemu-devel] [PATCH prep for-1.4? v2 0/2] prep_pci: Prepare for QOM realize Andreas Färber
2013-01-16 15:11 ` [Qemu-devel] [PATCH prep for-1.4? v2 1/2] prep_pci: Create PCIBus and PCIDevice in-place Andreas Färber
2013-01-16 15:11 ` [Qemu-devel] [PATCH prep for-1.4? v2 2/2] prep_pci: Convert to QOM realizefn Andreas Färber

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).