From patchwork Mon Mar 25 12:51:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang Zheng X-Patchwork-Id: 10869093 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 477641708 for ; Mon, 25 Mar 2019 12:54:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26AFD28399 for ; Mon, 25 Mar 2019 12:54:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 251B82854A; Mon, 25 Mar 2019 12:54:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BBEAC2865F for ; Mon, 25 Mar 2019 12:54:30 +0000 (UTC) Received: from localhost ([127.0.0.1]:42101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8P7V-0003SQ-G4 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Mar 2019 08:54:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8P6P-0002hQ-Pi for qemu-devel@nongnu.org; Mon, 25 Mar 2019 08:53:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h8P6O-0000DE-TA for qemu-devel@nongnu.org; Mon, 25 Mar 2019 08:53:21 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2254 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h8P6J-00009g-UQ; Mon, 25 Mar 2019 08:53:16 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 0C5BCEA9B759C78E26E2; Mon, 25 Mar 2019 20:53:06 +0800 (CST) Received: from HGHY1z004218071.china.huawei.com (10.177.29.32) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.408.0; Mon, 25 Mar 2019 20:52:57 +0800 From: Xiang Zheng To: , Date: Mon, 25 Mar 2019 20:51:42 +0800 Message-ID: <20190325125142.11628-1-zhengxiang9@huawei.com> X-Mailer: git-send-email 2.15.1.windows.2 MIME-Version: 1.0 X-Originating-IP: [10.177.29.32] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [RFC PATCH] hw/arm/virt: use variable size of flash device to save memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, ard.biesheuvel@linaro.org, Xiang Zheng , guoheyi@huawei.com, wanghaibin.wang@huawei.com, lersek@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently we fill the VIRT_FLASH space with two 64MB NOR images when using persistent UEFI variables on QEMU. Actually we only use a very small part of the memory while the rest significant large part of memory is wasted. This patch creates and maps a variable size of flash device instead of a mandatory 64MB one to save memory. Signed-off-by: Xiang Zheng Signed-off-by: Xiang Zheng --- This patch might be insufficient since it also needs to modify the flash size in ACPI and DTB. BTW, I don't understand why it requires the two NOR images to be exactly 64MB in size when using -pflash. --- hw/arm/virt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ce2664a..8269532 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -44,6 +44,7 @@ #include "sysemu/numa.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/block-backend.h" #include "hw/loader.h" #include "exec/address-spaces.h" #include "qemu/bitops.h" @@ -881,14 +882,18 @@ static void create_one_flash(const char *name, hwaddr flashbase, DriveInfo *dinfo = drive_get_next(IF_PFLASH); DeviceState *dev = qdev_create(NULL, TYPE_PFLASH_CFI01); SysBusDevice *sbd = SYS_BUS_DEVICE(dev); + BlockBackend *blk_backend = NULL; const uint64_t sectorlength = 256 * 1024; + hwaddr real_size = flashsize; if (dinfo) { - qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo), - &error_abort); + blk_backend = blk_by_legacy_dinfo(dinfo); + qdev_prop_set_drive(dev, "drive", blk_backend, &error_abort); + real_size = blk_getlength(blk_backend); + real_size = flashsize > real_size ? real_size : flashsize; } - qdev_prop_set_uint32(dev, "num-blocks", flashsize / sectorlength); + qdev_prop_set_uint32(dev, "num-blocks", real_size / sectorlength); qdev_prop_set_uint64(dev, "sector-length", sectorlength); qdev_prop_set_uint8(dev, "width", 4); qdev_prop_set_uint8(dev, "device-width", 2);