From patchwork Fri Oct 31 13:53:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 39899 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 320CD202FE for ; Fri, 31 Oct 2014 13:54:04 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id x13sf4139461wgg.5 for ; Fri, 31 Oct 2014 06:54:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=uaqLG1dupMM6a6oxQPoC/fmPZ5L71TMGn13hK1wPY7w=; b=elw3Hop095UcWrDemSlcvazpMJdGi2cDB7o3J4tddSKxstrpY7QGhCTmX8jPdd5eE/ IEaJDSDtWdBR+MoJ+KaNSyeSmgJxDeZojV5pUfHE9VFzHACRhMgleCNtd7fIEUMXVyKx ZNSSciqh7pQT7rjrkTMeS0nN0Qh84B36phdZ29b1Z575mBGllNm098J+vMTmdFhQdEQU jumrpskypWO2C1plOnGGryw1fpW6DkHDKL2odayEbpobKzW9Z33l7D8aI8ILe0b3welm 5yQoKdzlvQBJbxIW63l0KbaKFRmRXx1P9Ry9KIwD9nkCkO9pQHVAg08YwZV4dkkhKB4M pv2g== X-Gm-Message-State: ALoCoQlO3dXBx4i4WM24wM/jFSF7V6ejv1llAiliFeFbwLOrfkCHhFEIF1fr9zxDBHy0TCks2Vf1 X-Received: by 10.112.159.199 with SMTP id xe7mr26858lbb.21.1414763643042; Fri, 31 Oct 2014 06:54:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.7 with SMTP id i7ls383060laf.47.gmail; Fri, 31 Oct 2014 06:54:02 -0700 (PDT) X-Received: by 10.152.88.105 with SMTP id bf9mr26668627lab.30.1414763642901; Fri, 31 Oct 2014 06:54:02 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id rq6si16854643lbb.21.2014.10.31.06.54.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 06:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id b6so6005717lbj.20 for ; Fri, 31 Oct 2014 06:54:02 -0700 (PDT) X-Received: by 10.112.77.74 with SMTP id q10mr26197737lbw.66.1414763642785; Fri, 31 Oct 2014 06:54:02 -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.84.229 with SMTP id c5csp205561lbz; Fri, 31 Oct 2014 06:54:02 -0700 (PDT) X-Received: by 10.194.76.135 with SMTP id k7mr28706642wjw.94.1414763642099; Fri, 31 Oct 2014 06:54:02 -0700 (PDT) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com. [209.85.212.178]) by mx.google.com with ESMTPS id ba7si14213538wjb.133.2014.10.31.06.54.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 06:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.178 as permitted sender) client-ip=209.85.212.178; Received: by mail-wi0-f178.google.com with SMTP id q5so1370796wiv.5 for ; Fri, 31 Oct 2014 06:54:01 -0700 (PDT) X-Received: by 10.194.92.82 with SMTP id ck18mr27890519wjb.103.1414763641238; Fri, 31 Oct 2014 06:54:01 -0700 (PDT) Received: from midway01-04-00.lavalab ([88.98.47.97]) by mx.google.com with ESMTPSA id w13sm12167570wjq.29.2014.10.31.06.53.59 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 06:54:00 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, agraf@suse.de, pbonzini@redhat.com, kim.phillips@freescale.com, a.rigo@virtualopensystems.com, manish.jaggi@caviumnetworks.com, joel.schopp@amd.com Cc: eric.auger@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, will.deacon@arm.com, Bharat.Bhushan@freescale.com, stuart.yoder@freescale.com, a.motakis@virtualopensystems.com Subject: [PATCH v4 6/6] hw/arm/virt: add dynamic sysbus device support Date: Fri, 31 Oct 2014 13:53:32 +0000 Message-Id: <1414763612-4939-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1414763612-4939-1-git-send-email-eric.auger@linaro.org> References: <1414763612-4939-1-git-send-email-eric.auger@linaro.org> 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.217.175 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 a 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 start the VFIO dynamic device IRQ handling. Signed-off-by: Alexander Graf Signed-off-by: Eric Auger --- 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 Conflicts: hw/arm/sysbus-fdt.c --- hw/arm/virt.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 78f618d..3a09d58 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -42,6 +42,8 @@ #include "exec/address-spaces.h" #include "qemu/bitops.h" #include "qemu/error-report.h" +#include "hw/arm/sysbus-fdt.h" +#include "hw/platform-bus.h" #define NUM_VIRTIO_TRANSPORTS 32 @@ -59,6 +61,11 @@ #define GIC_FDT_IRQ_PPI_CPU_START 8 #define GIC_FDT_IRQ_PPI_CPU_WIDTH 8 +#define PLATFORM_BUS_BASE 0x9400000 +#define PLATFORM_BUS_SIZE (4ULL * 1024 * 1024) +#define PLATFORM_BUS_FIRST_IRQ 48 +#define PLATFORM_BUS_NUM_IRQS 20 + enum { VIRT_FLASH, VIRT_MEM, @@ -68,6 +75,7 @@ enum { VIRT_UART, VIRT_MMIO, VIRT_RTC, + VIRT_PLATFORM_BUS, }; typedef struct MemMapEntry { @@ -107,6 +115,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_GIC_CPU] = { 0x08010000, 0x00010000 }, [VIRT_UART] = { 0x09000000, 0x00001000 }, [VIRT_RTC] = { 0x09010000, 0x00001000 }, + [VIRT_PLATFORM_BUS] = {PLATFORM_BUS_BASE , PLATFORM_BUS_SIZE}, [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ /* 0x10000000 .. 0x40000000 reserved for PCI */ @@ -117,6 +126,14 @@ static const int a15irqmap[] = { [VIRT_UART] = 1, [VIRT_RTC] = 2, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ + [VIRT_PLATFORM_BUS] = PLATFORM_BUS_FIRST_IRQ, +}; + +ARMPlatformBusSystemParams platform_bus_params = { + .platform_bus_base = PLATFORM_BUS_BASE, + .platform_bus_size = PLATFORM_BUS_SIZE, + .platform_bus_first_irq = PLATFORM_BUS_FIRST_IRQ, + .platform_bus_num_irqs = PLATFORM_BUS_NUM_IRQS, }; static VirtBoardInfo machines[] = { @@ -519,6 +536,45 @@ static void create_flash(const VirtBoardInfo *vbi) g_free(nodename); } +static void create_platform_bus(VirtBoardInfo *vbi, qemu_irq *pic, + ARMPlatformBusSystemParams *system_params) +{ + DeviceState *dev; + SysBusDevice *s; + int i; + ARMPlatformBusFdtParams *fdt_params = g_new(ARMPlatformBusFdtParams, 1); + MemoryRegion *sysmem = get_system_memory(); + + /* + * register the notifier that will update the device tree with + * the platform bus and device tree nodes. Must be done before + * the instantiation of the platform bus device that registers + * the notifier that instantiates the dynamic sysbus devices + */ + fdt_params->system_params = system_params; + fdt_params->binfo = &vbi->bootinfo; + fdt_params->intc = "/intc"; + 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", + system_params->platform_bus_num_irqs); + qdev_prop_set_uint32(dev, "mmio_size", + system_params->platform_bus_size); + qdev_init_nofail(dev); + s = SYS_BUS_DEVICE(dev); + + for (i = 0; i < system_params->platform_bus_num_irqs; i++) { + int irqn = system_params->platform_bus_first_irq + i; + sysbus_connect_irq(s, i, pic[irqn]); + } + + memory_region_add_subregion(sysmem, + system_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; @@ -604,6 +660,8 @@ static void machvirt_init(MachineState *machine) */ create_virtio_devices(vbi, pic); + create_platform_bus(vbi, pic, &platform_bus_params); + vbi->bootinfo.ram_size = machine->ram_size; vbi->bootinfo.kernel_filename = machine->kernel_filename; vbi->bootinfo.kernel_cmdline = machine->kernel_cmdline; @@ -620,6 +678,7 @@ static QEMUMachine machvirt_a15_machine = { .desc = "ARM Virtual Machine", .init = machvirt_init, .max_cpus = 8, + .has_dynamic_sysbus = true, }; static void machvirt_machine_init(void)