From patchwork Tue Dec 9 10:29:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 42036 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5166B25E75 for ; Tue, 9 Dec 2014 10:30:28 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id hs14sf219350lab.5 for ; Tue, 09 Dec 2014 02:30:27 -0800 (PST) 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=ph2biQCx8U3jlkqiDxEURrEmUZXf6PVIpyNxKBNkZ88=; b=UhaurACrZ0I18cSUjji6x4ZrMoq3liSJU9hwDZtp9OiUehEq5WzI10GdayuQ+Ix2+d DHkdeOw3L4ATIFSB8EDk0Eod4ubEhIz2gk53XIlIf/W8l0hF5JfKluB08/svfdS303uE oQD8V5KzRueEeHarkcStMacy8uZO1NJYH3/BgKkJg5ICuV5VONKaU8+aoA5C4cqSGWXc HAP4OLr5fGh9MrW6nBjBe+L5us0+1ymJN8D4pm8xMUpJuDi05CmVklS2jLPG59XFBHiE f3Sk6qLO88J05QV0jUl3ciz7ZnEGNcARgrmQi1pHDlu2I8SubG07WXteP+Qv3JtLRFwR cziQ== X-Gm-Message-State: ALoCoQkUNzBRjeddzRyaTjKAToMt8Lid2nSG2srkw3BytDi1cHApFxg7rrsXoXuY9Ovw/nnw3PE5 X-Received: by 10.112.154.194 with SMTP id vq2mr262326lbb.10.1418121027240; Tue, 09 Dec 2014 02:30:27 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.227 with SMTP id u3ls18183laa.109.gmail; Tue, 09 Dec 2014 02:30:26 -0800 (PST) X-Received: by 10.152.115.230 with SMTP id jr6mr21165248lab.2.1418121026896; Tue, 09 Dec 2014 02:30:26 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id l8si845567lag.90.2014.12.09.02.30.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Dec 2014 02:30:26 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so252619lbj.27 for ; Tue, 09 Dec 2014 02:30:26 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr20736659lbo.32.1418121026752; Tue, 09 Dec 2014 02:30:26 -0800 (PST) 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.184.201 with SMTP id ew9csp733402lbc; Tue, 9 Dec 2014 02:30:25 -0800 (PST) X-Received: by 10.180.78.9 with SMTP id x9mr3104317wiw.39.1418121025226; Tue, 09 Dec 2014 02:30:25 -0800 (PST) Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com. [74.125.82.41]) by mx.google.com with ESMTPS id ls3si1359054wjb.54.2014.12.09.02.30.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Dec 2014 02:30:25 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.41 as permitted sender) client-ip=74.125.82.41; Received: by mail-wg0-f41.google.com with SMTP id y19so396308wgg.28 for ; Tue, 09 Dec 2014 02:30:25 -0800 (PST) X-Received: by 10.194.121.167 with SMTP id ll7mr3633476wjb.26.1418121020268; Tue, 09 Dec 2014 02:30:20 -0800 (PST) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id w4sm1129273wjw.39.2014.12.09.02.30.19 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Dec 2014 02:30:19 -0800 (PST) From: Eric Auger To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, a.rigo@virtualopensystems.com, kim.phillips@freescale.com, marc.zyngier@arm.com, manish.jaggi@caviumnetworks.com, joel.schopp@amd.com, zhaoshenglong@huawei.com, ard.biesheuvel@linaro.org, agraf@suse.de, peter.maydell@linaro.org, pbonzini@redhat.com, afaerber@suse.de Cc: eric.auger@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, Bharat.Bhushan@freescale.com, stuart.yoder@freescale.com, a.motakis@virtualopensystems.com, alex.williamson@redhat.com Subject: [PATCH v6 3/3] hw/arm/virt: add dynamic sysbus device support Date: Tue, 9 Dec 2014 10:29:59 +0000 Message-Id: <1418120999-12631-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1418120999-12631-1-git-send-email-eric.auger@linaro.org> References: <1418120999-12631-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.182 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: Alexander Graf Signed-off-by: Eric Auger --- 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 Conflicts: hw/arm/sysbus-fdt.c --- hw/arm/virt.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 314e55b..366083a 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,9 @@ #define GIC_FDT_IRQ_PPI_CPU_START 8 #define GIC_FDT_IRQ_PPI_CPU_WIDTH 8 +#define PLATFORM_BUS_FIRST_IRQ 48 +#define PLATFORM_BUS_NUM_IRQS 20 + enum { VIRT_FLASH, VIRT_MEM, @@ -68,8 +73,11 @@ enum { VIRT_UART, VIRT_MMIO, VIRT_RTC, + VIRT_PLATFORM_BUS, }; +static ARMPlatformBusSystemParams platform_bus_params; + typedef struct MemMapEntry { hwaddr base; hwaddr size; @@ -100,23 +108,25 @@ typedef struct VirtBoardInfo { */ static const MemMapEntry a15memmap[] = { /* Space up to 0x8000000 is reserved for a boot ROM */ - [VIRT_FLASH] = { 0, 0x08000000 }, - [VIRT_CPUPERIPHS] = { 0x08000000, 0x00020000 }, + [VIRT_FLASH] = { 0, 0x08000000 }, + [VIRT_CPUPERIPHS] = { 0x08000000, 0x00020000 }, /* GIC distributor and CPU interfaces sit inside the CPU peripheral space */ - [VIRT_GIC_DIST] = { 0x08000000, 0x00010000 }, - [VIRT_GIC_CPU] = { 0x08010000, 0x00010000 }, - [VIRT_UART] = { 0x09000000, 0x00001000 }, - [VIRT_RTC] = { 0x09010000, 0x00001000 }, - [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, + [VIRT_GIC_DIST] = { 0x08000000, 0x00010000 }, + [VIRT_GIC_CPU] = { 0x08010000, 0x00010000 }, + [VIRT_UART] = { 0x09000000, 0x00001000 }, + [VIRT_RTC] = { 0x09010000, 0x00001000 }, + [VIRT_PLATFORM_BUS] = { 0x09400000, 0x04000000 }, + [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ /* 0x10000000 .. 0x40000000 reserved for PCI */ - [VIRT_MEM] = { 0x40000000, 30ULL * 1024 * 1024 * 1024 }, + [VIRT_MEM] = { 0x40000000, 30ULL * 1024 * 1024 * 1024 }, }; static const int a15irqmap[] = { [VIRT_UART] = 1, [VIRT_RTC] = 2, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ + [VIRT_PLATFORM_BUS] = 48, }; static VirtBoardInfo machines[] = { @@ -519,6 +529,47 @@ static void create_flash(const VirtBoardInfo *vbi) 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; @@ -581,6 +632,24 @@ static void machvirt_init(MachineState *machine) object_property_set_bool(cpuobj, true, "realized", NULL); } + + /* + * register the arm_load_kernel machine init done notifier + * before platform_bus_create call. + * There, arm_register_platform_bus_fdt_creator registers another + * notifier that adds platform bus nodes. Notifiers are executed + * in registration reverse order. + */ + vbi->bootinfo.ram_size = machine->ram_size; + vbi->bootinfo.kernel_filename = machine->kernel_filename; + vbi->bootinfo.kernel_cmdline = machine->kernel_cmdline; + vbi->bootinfo.initrd_filename = machine->initrd_filename; + vbi->bootinfo.nb_cpus = smp_cpus; + vbi->bootinfo.board_id = -1; + vbi->bootinfo.loader_start = vbi->memmap[VIRT_MEM].base; + vbi->bootinfo.get_dtb = machvirt_dtb; + arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo); + fdt_add_timer_nodes(vbi); fdt_add_cpu_nodes(vbi); fdt_add_psci_node(vbi); @@ -604,15 +673,8 @@ static void machvirt_init(MachineState *machine) */ create_virtio_devices(vbi, pic); - vbi->bootinfo.ram_size = machine->ram_size; - vbi->bootinfo.kernel_filename = machine->kernel_filename; - vbi->bootinfo.kernel_cmdline = machine->kernel_cmdline; - vbi->bootinfo.initrd_filename = machine->initrd_filename; - vbi->bootinfo.nb_cpus = smp_cpus; - vbi->bootinfo.board_id = -1; - vbi->bootinfo.loader_start = vbi->memmap[VIRT_MEM].base; - vbi->bootinfo.get_dtb = machvirt_dtb; - arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo); + create_platform_bus(vbi, pic); + } static QEMUMachine machvirt_a15_machine = { @@ -620,6 +682,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)