From patchwork Tue Jun 2 11:29:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 49358 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6F2F220BD1 for ; Tue, 2 Jun 2015 11:29:53 +0000 (UTC) Received: by wgme6 with SMTP id e6sf39797990wgm.3 for ; Tue, 02 Jun 2015 04:29:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=I3iFkaGoeOq7J40Lmoy3WLbXH7uVluNfLq98BjGB3TI=; b=JTie0nV9oZoZKJjDXUaPLDJsGBOqSSxSqyw9hVs/QUFFNP8KYZYMro5sf100VV4xA7 PBvdRsKxois7TxpetbrF0FLLZ9iiImI9+wsf3jtV0Y/h1TOB4BkMwUD9GKAKAUOzszjr LgKVemqzvmqywKR/fyXJ/3Y32dPTV4dQ0TB2+YG9BowbAVOXe13qpNXgtz2WhH8CD7Ud BFTJa9oZp+3j4FpoCpC2UcRYPL0pJHw+oieDrFi4KIlbw/47/bTnT0yGSYo8BFaumU5R T1WWx9qS/brhQV6oHe2cAVAKJ/dlMkF/OwMsBIIhkMD8DtRlc6XylkMMIa83u29+iVRR 6hMg== X-Gm-Message-State: ALoCoQnixKl5BRIdwLX2mrNdh3WBpy57xCJUBdgOOT3hmSnAA6Xt5zlhXCJhmE3KJwmL/eTK5zmK X-Received: by 10.112.189.131 with SMTP id gi3mr25476892lbc.6.1433244592748; Tue, 02 Jun 2015 04:29:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.67 with SMTP id q3ls43876laq.78.gmail; Tue, 02 Jun 2015 04:29:52 -0700 (PDT) X-Received: by 10.112.25.10 with SMTP id y10mr25497904lbf.61.1433244592601; Tue, 02 Jun 2015 04:29:52 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id f2si14834688laa.43.2015.06.02.04.29.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2015 04:29:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by labko7 with SMTP id ko7so119286767lab.2 for ; Tue, 02 Jun 2015 04:29:52 -0700 (PDT) X-Received: by 10.152.27.1 with SMTP id p1mr25156277lag.112.1433244592493; Tue, 02 Jun 2015 04:29:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp2990933lbb; Tue, 2 Jun 2015 04:29:51 -0700 (PDT) X-Received: by 10.194.179.200 with SMTP id di8mr50555167wjc.56.1433244591607; Tue, 02 Jun 2015 04:29:51 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com. [209.85.212.179]) by mx.google.com with ESMTPS id fu6si16401350wic.110.2015.06.02.04.29.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2015 04:29:51 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.179 as permitted sender) client-ip=209.85.212.179; Received: by wiwd19 with SMTP id d19so15918388wiw.0 for ; Tue, 02 Jun 2015 04:29:51 -0700 (PDT) X-Received: by 10.180.210.162 with SMTP id mv2mr30203153wic.59.1433244591434; Tue, 02 Jun 2015 04:29:51 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id n6sm21110645wic.16.2015.06.02.04.29.48 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Jun 2015 04:29:49 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: kvmarm@lists.cs.columbia.edu, patches@linaro.org Subject: [PATCH v13 3/4] hw/arm/virt: add dynamic sysbus device support Date: Tue, 2 Jun 2015 12:29:13 +0100 Message-Id: <1433244554-12898-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1433244554-12898-1-git-send-email-eric.auger@linaro.org> References: <1433244554-12898-1-git-send-email-eric.auger@linaro.org> MIME-Version: 1.0 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Allows sysbus devices to be instantiated from command line by using -device option. Machvirt creates a platform bus at init. The dynamic sysbus devices are attached to this platform bus device. The platform bus device registers a machine init done notifier whose role will be to bind the dynamic sysbus devices. Indeed dynamic sysbus devices are created after machine init. machvirt also registers a notifier that will build the device tree nodes for the platform bus and its children dynamic sysbus devices. Signed-off-by: Eric Auger Reviewed-by: Alex Bennée --- v12 -> v13: - Changed start IRQ number of platform bus to 112 after the addition of MSI range v11 -> v12: - resize PLATFORM_BUS_NUM_IRQS to 64 instead of 32 - overall NUM_IRQS changed to 256. This leaves space for MSI looming addition - VIRT_PLATFORM_BUS size changed from 4MB to 32MB and base set at 0xc000000 - Add Alex R-b v8 -> v9: - PLATFORM_BUS_NUM_IRQS set to 32 instead of 20 - platform bus irq now start at 64 instead of 48 - remove change of indentation in a15memmap - correct misc style issues v7 -> v8: - rebase on 2.2.0 - in machvirt_init, create_platform_bus simply is added after the arm_load_kernel call instead of moving this latter. Related comment slighly reworded. - Due to those changes I dropped Alex and Shannon's Reviewed-by v6 -> v7: Take into account Shannon comments: - remove PLATFORM_BUS_FIRST_IRQ macro - correct platform bus size to 0x400000 - add an additional comment in a15irqmap related to PLATFORM_BUS_NUM_IRQS v5 -> v6: - Take into account Peter's comments: - platform_bus_params initialized from vbi->memmap and vbi->irqmap. As a consequence, const is removed. Also alignment in a15memmap is slightly changed. - ARMPlatformBusSystemParams handle removed from create_platform_bus prototype - arm_load_kernel has become a machine init done notifier registration. It must be called before platform_bus_create to guarantee the correct notifier execution sequence v4 -> v5: - platform_bus_params becomes static const - reword comment in create_platform_bus - reword the commit message v3 -> v4: - use platform bus object, instantiated in create_platform_bus - device tree generation for platform bus and children dynamic sysbus devices is no more handled at reset but in a machine_init_done_notifier (due to the change in implementaion of ARM load dtb using rom_add_blob_fixed). - device tree enhancement now takes into account the case of user provided dtb. Before the user dtb was overwritten which was wrong. However in case the dtb is provided by the user, dynamic sysbus nodes are not added there. - renaming of MACHVIRT_PLATFORM defines - MACHVIRT_PLATFORM_PAGE_SHIFT and SIZE_PAGES not needed anymore, hence removed. - DynSysbusParams struct renamed into ARMPlatformBusSystemParams and above params removed. - separation of dt creation and QEMU binding is not mandated anymore since the device tree is not created from scratch anymore. Instead the modify_dtb function is used. - create_platform_bus registers another machine init done notifier to start VFIO IRQ handling. This latter executes after the dynamic sysbus device binding. v2 -> v3: - renaming of arm_platform_bus_create_devtree and arm_load_dtb - add copyright in hw/arm/dyn_sysbus_devtree.c v1 -> v2: - remove useless vfio-platform.h include file - s/MACHVIRT_PLATFORM_HOLE/MACHVIRT_PLATFORM_SIZE - use dyn_sysbus_binding and dyn_sysbus_devtree - dynamic sysbus platform buse size shrinked to 4MB and moved between RTC and MMIO v1: Inspired from what Alex Graf did in ppc e500 https://lists.gnu.org/archive/html/qemu-ppc/2014-07/msg00012.html --- hw/arm/virt.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++- include/hw/arm/virt.h | 1 + 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 4bb7175..02b91ba 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -45,9 +45,11 @@ #include "qemu/error-report.h" #include "hw/pci-host/gpex.h" #include "hw/arm/virt-acpi-build.h" +#include "hw/arm/sysbus-fdt.h" +#include "hw/platform-bus.h" /* Number of external interrupt lines to configure the GIC with */ -#define NUM_IRQS 128 +#define NUM_IRQS 256 #define GIC_FDT_IRQ_TYPE_SPI 0 #define GIC_FDT_IRQ_TYPE_PPI 1 @@ -60,6 +62,10 @@ #define GIC_FDT_IRQ_PPI_CPU_START 8 #define GIC_FDT_IRQ_PPI_CPU_WIDTH 8 +#define PLATFORM_BUS_NUM_IRQS 64 + +static ARMPlatformBusSystemParams platform_bus_params; + typedef struct VirtBoardInfo { struct arm_boot_info bootinfo; const char *cpu_model; @@ -116,6 +122,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_FW_CFG] = { 0x09020000, 0x0000000a }, [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ + [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 }, [VIRT_PCIE_MMIO] = { 0x10000000, 0x2eff0000 }, [VIRT_PCIE_PIO] = { 0x3eff0000, 0x00010000 }, [VIRT_PCIE_ECAM] = { 0x3f000000, 0x01000000 }, @@ -128,6 +135,7 @@ static const int a15irqmap[] = { [VIRT_PCIE] = 3, /* ... to 6 */ [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ + [VIRT_PLATFORM_BUS] = 112, /* ...to 112 + PLATFORM_BUS_NUM_IRQS -1 */ }; static VirtBoardInfo machines[] = { @@ -728,6 +736,47 @@ static void create_pcie(const VirtBoardInfo *vbi, qemu_irq *pic) g_free(nodename); } +static void create_platform_bus(VirtBoardInfo *vbi, qemu_irq *pic) +{ + DeviceState *dev; + SysBusDevice *s; + int i; + ARMPlatformBusFDTParams *fdt_params = g_new(ARMPlatformBusFDTParams, 1); + MemoryRegion *sysmem = get_system_memory(); + + platform_bus_params.platform_bus_base = vbi->memmap[VIRT_PLATFORM_BUS].base; + platform_bus_params.platform_bus_size = vbi->memmap[VIRT_PLATFORM_BUS].size; + platform_bus_params.platform_bus_first_irq = vbi->irqmap[VIRT_PLATFORM_BUS]; + platform_bus_params.platform_bus_num_irqs = PLATFORM_BUS_NUM_IRQS; + + fdt_params->system_params = &platform_bus_params; + fdt_params->binfo = &vbi->bootinfo; + fdt_params->intc = "/intc"; + /* + * register a machine init done notifier that creates the device tree + * nodes of the platform bus and its children dynamic sysbus devices + */ + arm_register_platform_bus_fdt_creator(fdt_params); + + dev = qdev_create(NULL, TYPE_PLATFORM_BUS_DEVICE); + dev->id = TYPE_PLATFORM_BUS_DEVICE; + qdev_prop_set_uint32(dev, "num_irqs", + platform_bus_params.platform_bus_num_irqs); + qdev_prop_set_uint32(dev, "mmio_size", + platform_bus_params.platform_bus_size); + qdev_init_nofail(dev); + s = SYS_BUS_DEVICE(dev); + + for (i = 0; i < platform_bus_params.platform_bus_num_irqs; i++) { + int irqn = platform_bus_params.platform_bus_first_irq + i; + sysbus_connect_irq(s, i, pic[irqn]); + } + + memory_region_add_subregion(sysmem, + platform_bus_params.platform_bus_base, + sysbus_mmio_get_region(s, 0)); +} + static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size) { const VirtBoardInfo *board = (const VirtBoardInfo *)binfo; @@ -865,6 +914,14 @@ static void machvirt_init(MachineState *machine) vbi->bootinfo.get_dtb = machvirt_dtb; vbi->bootinfo.firmware_loaded = bios_name || drive_get(IF_PFLASH, 0, 0); arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo); + + /* + * arm_load_kernel machine init done notifier registration must + * happen before the platform_bus_create call. In this latter, + * another notifier is registered which adds platform bus nodes. + * Notifiers are executed in registration reverse order. + */ + create_platform_bus(vbi, pic); } static bool virt_get_secure(Object *obj, Error **errp) @@ -903,6 +960,7 @@ static void virt_class_init(ObjectClass *oc, void *data) mc->desc = "ARM Virtual Machine", mc->init = machvirt_init; mc->max_cpus = 8; + mc->has_dynamic_sysbus = true; } static const TypeInfo machvirt_info = { diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 003ef29..d22fd8e 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -55,6 +55,7 @@ enum { VIRT_PCIE_PIO, VIRT_PCIE_ECAM, VIRT_GIC_V2M, + VIRT_PLATFORM_BUS, }; typedef struct MemMapEntry {