From patchwork Thu Jan 24 08:34:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 215269 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3AA9D2C007E for ; Thu, 24 Jan 2013 19:34:52 +1100 (EST) Received: from localhost ([::1]:52438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyIGo-0006r2-Ch for incoming@patchwork.ozlabs.org; Thu, 24 Jan 2013 03:34:50 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyIGS-00067R-7L for qemu-devel@nongnu.org; Thu, 24 Jan 2013 03:34:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TyIGL-0000Id-Bv for qemu-devel@nongnu.org; Thu, 24 Jan 2013 03:34:27 -0500 Received: from mout.web.de ([212.227.17.11]:64071) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyIGL-0000IP-2n; Thu, 24 Jan 2013 03:34:21 -0500 Received: from localhost.localdomain ([84.148.60.98]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0Lo0dI-1Udwfp0qFc-00g48a; Thu, 24 Jan 2013 09:34:17 +0100 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Thu, 24 Jan 2013 09:34:06 +0100 Message-Id: <1359016447-23268-2-git-send-email-andreas.faerber@web.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359016447-23268-1-git-send-email-andreas.faerber@web.de> References: <1359016447-23268-1-git-send-email-andreas.faerber@web.de> MIME-Version: 1.0 X-Provags-ID: V02:K0:lkcdKy8/oMfkn7ZxMHKGOEYaJj3v6sflPl2wHDfqY+b SpJUOijZXPEQkhSVN8TDLTszFL50X2DuXJeQtJEKKSNEbrclRK A4xCiMnQ+ywtTQlXjo8YIU4fWzJrIEpeB9UbaqQgA1uZ760V2m txHIItfDgZEEhhbClVId1nXPloNl48f/16K/RJWlQFIHkOs2St gAebnN75DgdXYa9jbW3FA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.17.11 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , qemu-ppc@nongnu.org Subject: [Qemu-devel] [PATCH prep for-1.4 v3 1/2] prep_pci: Create PCIBus and PCIDevice in-place X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Prepares for QOM realizefn by removing object creation from qdev initfn. Signed-off-by: Andreas Färber --- hw/prep_pci.c | 50 +++++++++++++++++++++++++++++++++++++------------- 1 Datei geändert, 37 Zeilen hinzugefügt(+), 13 Zeilen entfernt(-) diff --git a/hw/prep_pci.c b/hw/prep_pci.c index 212a2ac..e1420ca 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,29 @@ 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 int raven_init(PCIDevice *d) @@ -176,7 +199,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 +219,7 @@ 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, .class_init = raven_pcihost_class_init, };