From patchwork Sun Mar 24 11:32:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 15559 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A161523E3E for ; Sun, 24 Mar 2013 11:32:46 +0000 (UTC) Received: from mail-vb0-f46.google.com (mail-vb0-f46.google.com [209.85.212.46]) by fiordland.canonical.com (Postfix) with ESMTP id 3FD28A18D65 for ; Sun, 24 Mar 2013 11:32:46 +0000 (UTC) Received: by mail-vb0-f46.google.com with SMTP id b13so3428486vby.33 for ; Sun, 24 Mar 2013 04:32:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=wKtTz7YY5OLF0G2C202ZL06lt8nYjbvmIr1F3fOxJIs=; b=YLGU9kFzGq7uFZO8IZSsA0j266NcZJZBmlnhPYx1AeOAr5Vy6YtyP9J5lVtI7BKajy 7dY+rKgM+80ZVBmw8xJLrn+SYtpksaVGoHWgwijXyDzn22yv05YXAgYe0ZkbJ64xSRaA +N/gPt7hyU8/5W6PuD7/CwNGkGPrRb7C7u93nyvS8lzjGp3SJqKMa1z9Eto0bgHAwFzI Ym5fXctyG7wLUmJrf/t48kJe5Vn0B18GxL1yeSJuNIXVWeeOWW6F288/fMsE2ZdylSJe Tu8rv9A6/SNUT9M80JqPAM52xzBEWuz2Tr5sXJjkxzC2NCAPplWc/b0iroTcA/b70uEU K2wQ== X-Received: by 10.52.93.20 with SMTP id cq20mr9131291vdb.38.1364124765660; Sun, 24 Mar 2013 04:32:45 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.59.4.204 with SMTP id cg12csp4954ved; Sun, 24 Mar 2013 04:32:44 -0700 (PDT) X-Received: by 10.204.190.143 with SMTP id di15mr3776122bkb.50.1364124764241; Sun, 24 Mar 2013 04:32:44 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id ge5si2806139bkc.159.2013.03.24.04.32.43 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 24 Mar 2013 04:32:44 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1UJjAG-0001W1-7k; Sun, 24 Mar 2013 11:32:40 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , "Michael S. Tsirkin" , Paul Brook , Arnd Bergmann , Will Deacon Subject: [PATCH 04/10] versatile_pci: Change to subclassing TYPE_PCI_HOST_BRIDGE Date: Sun, 24 Mar 2013 11:32:34 +0000 Message-Id: <1364124760-5794-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1364124760-5794-1-git-send-email-peter.maydell@linaro.org> References: <1364124760-5794-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQk8Wj4yUzy4z8zq5r7GsI+b6UarpM3sbmFxQhpnAFTAx1oIn6fJUSzHgZwfXqESLFoFlk/1 Change versatile_pci to subclass TYPE_PCI_HOST_BRIDGE and generally handle PCI in a more QOM-like fashion. Signed-off-by: Peter Maydell --- hw/versatile_pci.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/hw/versatile_pci.c b/hw/versatile_pci.c index 541f6b5..dfd3001 100644 --- a/hw/versatile_pci.c +++ b/hw/versatile_pci.c @@ -9,16 +9,22 @@ #include "hw/sysbus.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "exec/address-spaces.h" typedef struct { - SysBusDevice busdev; + PCIHostState parent_obj; + qemu_irq irq[4]; - int realview; MemoryRegion mem_config; MemoryRegion mem_config2; MemoryRegion isa; + PCIBus pci_bus; + PCIDevice pci_dev; + + /* Constant for life of device: */ + int realview; } PCIVPBState; #define TYPE_VERSATILE_PCI "versatile_pci" @@ -66,20 +72,31 @@ static void pci_vpb_set_irq(void *opaque, int irq_num, int level) qemu_set_irq(pic[irq_num], level); } +static void pci_vpb_init(Object *obj) +{ + PCIHostState *h = PCI_HOST_BRIDGE(obj); + PCIVPBState *s = PCI_VPB(obj); + + pci_bus_new_inplace(&s->pci_bus, DEVICE(obj), "pci", + get_system_memory(), get_system_io(), + PCI_DEVFN(11, 0)); + h->bus = &s->pci_bus; + + object_initialize(&s->pci_dev, TYPE_VERSATILE_PCI_HOST); + qdev_set_parent_bus(DEVICE(&s->pci_dev), BUS(&s->pci_bus)); +} + static void pci_vpb_realize(DeviceState *dev, Error **errp) { PCIVPBState *s = PCI_VPB(dev); SysBusDevice *sbd = SYS_BUS_DEVICE(dev); - PCIBus *bus; int i; for (i = 0; i < 4; i++) { sysbus_init_irq(sbd, &s->irq[i]); } - bus = pci_register_bus(dev, "pci", - pci_vpb_set_irq, pci_vpb_map_irq, s->irq, - get_system_memory(), get_system_io(), - PCI_DEVFN(11, 0), 4); + + pci_bus_irqs(&s->pci_bus, pci_vpb_set_irq, pci_vpb_map_irq, s->irq, 4); /* ??? Register memory space. */ @@ -88,16 +105,17 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp) * 1 : PCI config window * 2 : PCI IO window */ - memory_region_init_io(&s->mem_config, &pci_vpb_config_ops, bus, + memory_region_init_io(&s->mem_config, &pci_vpb_config_ops, &s->pci_bus, "pci-vpb-selfconfig", 0x1000000); sysbus_init_mmio(sbd, &s->mem_config); - memory_region_init_io(&s->mem_config2, &pci_vpb_config_ops, bus, + memory_region_init_io(&s->mem_config2, &pci_vpb_config_ops, &s->pci_bus, "pci-vpb-config", 0x1000000); sysbus_init_mmio(sbd, &s->mem_config2); isa_mmio_setup(&s->isa, 0x0100000); sysbus_init_mmio(sbd, &s->isa); - pci_create_simple(bus, -1, "versatile_pci_host"); + /* TODO Remove once realize propagates to child devices. */ + object_property_set_bool(OBJECT(&s->pci_dev), true, "realized", errp); } static int versatile_pci_host_init(PCIDevice *d) @@ -134,8 +152,9 @@ static void pci_vpb_class_init(ObjectClass *klass, void *data) static const TypeInfo pci_vpb_info = { .name = TYPE_VERSATILE_PCI, - .parent = TYPE_SYS_BUS_DEVICE, + .parent = TYPE_PCI_HOST_BRIDGE, .instance_size = sizeof(PCIVPBState), + .instance_init = pci_vpb_init, .class_init = pci_vpb_class_init, };