From patchwork Fri Sep 5 15:15:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36857 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f69.google.com (mail-qg0-f69.google.com [209.85.192.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5CA9F202E4 for ; Fri, 5 Sep 2014 15:18:00 +0000 (UTC) Received: by mail-qg0-f69.google.com with SMTP id q108sf7327579qgd.0 for ; Fri, 05 Sep 2014 08:18:00 -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:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=+kQp+Xrsjyk98e8Xav0+8rIAiR85/IcFni/JkbsMQs8=; b=Lq7n1ZgtaxmJeJLEHDjxvbDQRcHi2jDOEXoERowv0y9CUXBjU4322W+afaTH+uahj8 LBFX+/GLlXM36HSypytn9+tqYXJiJa2/iIvCWZjExrDbQJmIpYd8gVeqk0pqcIYz2drg JDsVOI8JFRFn+JkCxgtJwlaou6rXH0yHbMSsSbUX555XnAs5ir0bWh9K34/N8ZYiVOum TsqPC4UCjAiGDw/IlcJ9oHNpRklcL8TTPpvitCmwFWdkhkJnkW8cpBeWJ88jlSU0mzke TaNYWAzIoC3HNuvS2mbx9CCJmzJI6kJgC0Tl0WPikJK8xBot4tud8R0DgT3HRWTqJ9zU a1XQ== X-Gm-Message-State: ALoCoQnZayhBK2nKJIWsG3YFvGrmSiuTmuc18YGI6cLpAvxcDIyTMsPg21FhItvMYcUoyp0RefWI X-Received: by 10.52.186.103 with SMTP id fj7mr7200752vdc.8.1409930279996; Fri, 05 Sep 2014 08:17:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.231 with SMTP id v94ls802021qgd.14.gmail; Fri, 05 Sep 2014 08:17:59 -0700 (PDT) X-Received: by 10.220.167.9 with SMTP id o9mr11408641vcy.8.1409930279716; Fri, 05 Sep 2014 08:17:59 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id rx9si1512672vdc.64.2014.09.05.08.17.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 08:17:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id id10so12438345vcb.2 for ; Fri, 05 Sep 2014 08:17:59 -0700 (PDT) X-Received: by 10.220.169.72 with SMTP id x8mr1734447vcy.45.1409930279481; Fri, 05 Sep 2014 08:17:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp97742vcb; Fri, 5 Sep 2014 08:17:59 -0700 (PDT) X-Received: by 10.140.38.73 with SMTP id s67mr18925140qgs.4.1409930278882; Fri, 05 Sep 2014 08:17:58 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id a8si1996174qat.48.2014.09.05.08.17.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 05 Sep 2014 08:17:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Received: from localhost ([::1]:58423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPvGw-0007Dg-Gk for patch@linaro.org; Fri, 05 Sep 2014 11:17:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPvEh-0003mn-WF for qemu-devel@nongnu.org; Fri, 05 Sep 2014 11:15:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPvEZ-0002jz-Uu for qemu-devel@nongnu.org; Fri, 05 Sep 2014 11:15:39 -0400 Received: from mail-wg0-f52.google.com ([74.125.82.52]:39056) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPvEZ-0002jh-LW for qemu-devel@nongnu.org; Fri, 05 Sep 2014 11:15:31 -0400 Received: by mail-wg0-f52.google.com with SMTP id m15so11710356wgh.11 for ; Fri, 05 Sep 2014 08:15:28 -0700 (PDT) X-Received: by 10.194.205.196 with SMTP id li4mr15321069wjc.46.1409930126443; Fri, 05 Sep 2014 08:15:26 -0700 (PDT) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id wx3sm1734308wjc.19.2014.09.05.08.15.25 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 08:15:25 -0700 (PDT) From: Ard Biesheuvel To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Fri, 5 Sep 2014 17:15:21 +0200 Message-Id: <1409930126-28449-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409930126-28449-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409930126-28449-1-git-send-email-ard.biesheuvel@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.52 Cc: fu.wei@linaro.org, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH 1/6] hw/arm/virt: Provide flash devices for boot ROMs 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@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.220.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell Add two flash devices to the virt board, so that it can be used for running guests which want a bootrom image such as UEFI. We provide two flash devices to make it more convenient to provide both a read-only UEFI image and a read-write place to store guest-set UEFI config variables. The '-bios' command line option is set up to provide an image for the first of the two flash devices. Signed-off-by: Peter Maydell Reviewed-by: Paolo Bonzini --- hw/arm/virt.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 5853bb3ee4d5..c7f3680d6460 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -37,6 +37,7 @@ #include "sysemu/sysemu.h" #include "sysemu/kvm.h" #include "hw/boards.h" +#include "hw/loader.h" #include "exec/address-spaces.h" #include "qemu/bitops.h" #include "qemu/error-report.h" @@ -435,6 +436,73 @@ static void create_virtio_devices(const VirtBoardInfo *vbi, qemu_irq *pic) } } +static void create_one_flash(const char *name, hwaddr flashbase, + hwaddr flashsize) +{ + /* Create and map a single flash device. We use the same + * parameters as the flash devices on the Versatile Express board. + */ + DriveInfo *dinfo = drive_get_next(IF_PFLASH); + DeviceState *dev = qdev_create(NULL, "cfi.pflash01"); + const uint64_t sectorlength = 256 * 1024; + + if (dinfo && qdev_prop_set_drive(dev, "drive", dinfo->bdrv)) { + abort(); + } + + qdev_prop_set_uint32(dev, "num-blocks", flashsize / sectorlength); + qdev_prop_set_uint64(dev, "sector-length", sectorlength); + qdev_prop_set_uint8(dev, "width", 4); + qdev_prop_set_uint8(dev, "device-width", 2); + qdev_prop_set_uint8(dev, "big-endian", 0); + qdev_prop_set_uint16(dev, "id0", 0x89); + qdev_prop_set_uint16(dev, "id1", 0x18); + qdev_prop_set_uint16(dev, "id2", 0x00); + qdev_prop_set_uint16(dev, "id3", 0x00); + qdev_prop_set_string(dev, "name", name); + qdev_init_nofail(dev); + + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, flashbase); +} + +static void create_flash(const VirtBoardInfo *vbi) +{ + /* Create two flash devices to fill the VIRT_FLASH space in the memmap. + * Any file passed via -bios goes in the first of these. + */ + hwaddr flashsize = vbi->memmap[VIRT_FLASH].size / 2; + hwaddr flashbase = vbi->memmap[VIRT_FLASH].base; + char *nodename; + + if (bios_name) { + const char *fn; + + if (drive_get(IF_PFLASH, 0, 0)) { + error_report("The contents of the first flash device may be " + "specified with -bios or with -drive if=pflash... " + "but you cannot use both options at once"); + exit(1); + } + fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + if (!fn || load_image_targphys(fn, flashbase, flashsize) < 0) { + error_report("Could not load ROM image '%s'", bios_name); + exit(1); + } + } + + create_one_flash("virt.flash0", flashbase, flashsize); + create_one_flash("virt.flash1", flashbase + flashsize, flashsize); + + nodename = g_strdup_printf("/flash@%" PRIx64, flashbase); + qemu_fdt_add_subnode(vbi->fdt, nodename); + qemu_fdt_setprop_string(vbi->fdt, nodename, "compatible", "cfi-flash"); + qemu_fdt_setprop_sized_cells(vbi->fdt, nodename, "reg", + 2, flashbase, 2, flashsize, + 2, flashbase + flashsize, 2, flashsize); + qemu_fdt_setprop_cell(vbi->fdt, nodename, "bank-width", 4); + g_free(nodename); +} + static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size) { const VirtBoardInfo *board = (const VirtBoardInfo *)binfo; @@ -514,6 +582,8 @@ static void machvirt_init(MachineState *machine) vmstate_register_ram_global(ram); memory_region_add_subregion(sysmem, vbi->memmap[VIRT_MEM].base, ram); + create_flash(vbi); + create_gic(vbi, pic); create_uart(vbi, pic);