From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49928) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvUep-0003CI-Py for qemu-devel@nongnu.org; Wed, 16 Jan 2013 10:12:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvUel-00032h-6I for qemu-devel@nongnu.org; Wed, 16 Jan 2013 10:12:03 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 16 Jan 2013 16:11:46 +0100 Message-Id: <1358349107-19592-2-git-send-email-afaerber@suse.de> In-Reply-To: <1358349107-19592-1-git-send-email-afaerber@suse.de> References: <1358349107-19592-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH prep for-1.4? v2 1/2] prep_pci: Create PCIBus and PCIDevice in-place List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, =?UTF-8?q?Andreas=20F=C3=A4rber?= , "open list:PReP" , anthony@codemonkey.ws From: Andreas F=C3=A4rber Prepares for QOM realizefn by removing object creation from qdev initfn. Signed-off-by: Andreas F=C3=A4rber --- hw/prep_pci.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-------= ------ 1 Datei ge=C3=A4ndert, 46 Zeilen hinzugef=C3=BCgt(+), 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=C3=A4rber * * 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 @@ =20 #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" =20 +#define TYPE_RAVEN_PCI_DEVICE "raven" #define TYPE_RAVEN_PCI_HOST_BRIDGE "raven-pcihost" =20 +#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) =20 @@ -38,12 +48,10 @@ typedef struct PRePPCIState { =20 MemoryRegion intack; qemu_irq irq[4]; + PCIBus pci_bus; + RavenPCIState pci_dev; } PREPPCIState; =20 -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 =3D PCI_HOST_BRIDGE(dev); PREPPCIState *s =3D RAVEN_PCI_HOST_BRIDGE(dev); MemoryRegion *address_space_mem =3D get_system_memory(); - MemoryRegion *address_space_io =3D get_system_io(); - PCIBus *bus; int i; =20 for (i =3D 0; i < 4; i++) { sysbus_init_irq(dev, &s->irq[i]); } =20 - bus =3D pci_register_bus(DEVICE(dev), NULL, - prep_set_irq, prep_map_irq, s->irq, - address_space_mem, address_space_io, 0, 4); - h->bus =3D bus; + pci_bus_irqs(&s->pci_bus, prep_set_irq, prep_map_irq, s->irq, 4); =20 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) =20 memory_region_init_io(&s->intack, &PPC_intack_ops, s, "pci-intack", = 1); memory_region_add_subregion(address_space_mem, 0xbffffff0, &s->intac= k); - pci_create_simple(bus, 0, "raven"); =20 - 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 =3D PCI_HOST_BRIDGE(obj); + PREPPCIState *s =3D RAVEN_PCI_HOST_BRIDGE(obj); + MemoryRegion *address_space_mem =3D get_system_memory(); + MemoryRegion *address_space_io =3D 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 =3D &s->pci_bus; + + object_initialize(&s->pci_dev, TYPE_RAVEN_PCI_DEVICE); + pci_dev =3D 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 =3D RAVEN_PCI_HOST_BRIDGE(obj); + + object_unref(OBJECT(&s->pci_bus)); + object_unref(OBJECT(&s->pci_dev)); } =20 static int raven_init(PCIDevice *d) @@ -176,7 +207,7 @@ static void raven_class_init(ObjectClass *klass, void= *data) } =20 static const TypeInfo raven_info =3D { - .name =3D "raven", + .name =3D TYPE_RAVEN_PCI_DEVICE, .parent =3D TYPE_PCI_DEVICE, .instance_size =3D sizeof(RavenPCIState), .class_init =3D raven_class_init, @@ -196,6 +227,8 @@ static const TypeInfo raven_pcihost_info =3D { .name =3D TYPE_RAVEN_PCI_HOST_BRIDGE, .parent =3D TYPE_PCI_HOST_BRIDGE, .instance_size =3D sizeof(PREPPCIState), + .instance_init =3D raven_pcihost_initfn, + .instance_finalize =3D raven_pcihost_finalizefn, .class_init =3D raven_pcihost_class_init, }; =20 --=20 1.7.10.4