From nobody Tue Feb 10 01:44:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553518497774987.0137232194726; Mon, 25 Mar 2019 05:54:57 -0700 (PDT) Received: from localhost ([127.0.0.1]:42101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h8P7o-0003SQ-An for importer@patchew.org; Mon, 25 Mar 2019 08:54:48 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- This patch might be insufficient since it also needs to modify the flash si= ze in ACPI and DTB. BTW, I don't understand why it requires the two NOR images to be exactly 64= MB 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 =3D drive_get_next(IF_PFLASH); DeviceState *dev =3D qdev_create(NULL, TYPE_PFLASH_CFI01); SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); + BlockBackend *blk_backend =3D NULL; const uint64_t sectorlength =3D 256 * 1024; + hwaddr real_size =3D flashsize; =20 if (dinfo) { - qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo), - &error_abort); + blk_backend =3D blk_by_legacy_dinfo(dinfo); + qdev_prop_set_drive(dev, "drive", blk_backend, &error_abort); + real_size =3D blk_getlength(blk_backend); + real_size =3D flashsize > real_size ? real_size : flashsize; } =20 - 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); --=20 1.8.3.1