All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-arm] [RFC PATCH] hw/arm/virt: use variable size of flash device to save memory
@ 2019-03-25 12:51 Xiang Zheng
  2019-03-25 13:11 ` Peter Maydell
  0 siblings, 1 reply; 50+ messages in thread
From: Xiang Zheng @ 2019-03-25 12:51 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: peter.maydell, ard.biesheuvel, Xiang Zheng, guoheyi,
	wanghaibin.wang, lersek

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 <zhengxiang9@huawei.com>
---

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);
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 50+ messages in thread

end of thread, other threads:[~2019-04-22  1:48 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-25 12:51 [Qemu-arm] [RFC PATCH] hw/arm/virt: use variable size of flash device to save memory Xiang Zheng
2019-03-25 13:11 ` Peter Maydell
2019-03-25 14:03   ` Zheng Xiang
2019-03-26  6:17     ` [Qemu-arm] [Qemu-devel] " Markus Armbruster
2019-03-26 11:03       ` Laszlo Ersek
2019-03-26 16:39         ` Markus Armbruster
2019-03-26 17:10           ` Laszlo Ersek
2019-03-26 18:36             ` Markus Armbruster
2019-04-03 14:12               ` [Qemu-arm] " Xiang Zheng
2019-04-03 14:12                 ` Xiang Zheng
2019-04-03 15:35                 ` [Qemu-arm] " Laszlo Ersek
2019-04-03 15:35                   ` Laszlo Ersek
2019-04-08 13:43                   ` [Qemu-arm] " Xiang Zheng
2019-04-08 13:43                     ` Xiang Zheng
2019-04-08 16:14                     ` [Qemu-arm] " Laszlo Ersek
2019-04-08 16:14                       ` Laszlo Ersek
2019-04-09  3:39                       ` [Qemu-arm] " Xiang Zheng
2019-04-09  3:39                         ` Xiang Zheng
2019-04-09  6:01                       ` [Qemu-arm] " Markus Armbruster
2019-04-09  6:01                         ` Markus Armbruster
2019-04-09  6:01                         ` Markus Armbruster
2019-04-09  8:28                         ` [Qemu-arm] " Kevin Wolf
2019-04-09  8:28                           ` Kevin Wolf
2019-04-09  8:28                           ` Kevin Wolf
2019-04-10  8:36                           ` [Qemu-arm] " Xiang Zheng
2019-04-10  8:36                             ` Xiang Zheng
2019-04-10  8:36                             ` Xiang Zheng
2019-04-11  7:15                             ` [Qemu-arm] " Markus Armbruster
2019-04-11  7:15                               ` Markus Armbruster
2019-04-12  9:26                               ` [Qemu-arm] " Xiang Zheng
2019-04-12  9:26                                 ` Xiang Zheng
2019-04-11 12:22                             ` [Qemu-arm] " Kevin Wolf
2019-04-11 12:22                               ` Kevin Wolf
2019-04-11 12:22                               ` Kevin Wolf
2019-04-12  1:52                               ` [Qemu-arm] " Xiang Zheng
2019-04-12  1:52                                 ` Xiang Zheng
2019-04-12  1:52                                 ` Xiang Zheng
2019-04-12  9:50                                 ` [Qemu-arm] " Xiang Zheng
2019-04-12  9:50                                   ` Xiang Zheng
2019-04-12  9:50                                   ` Xiang Zheng
2019-04-12 10:57                                   ` [Qemu-arm] " Kevin Wolf
2019-04-12 10:57                                     ` Kevin Wolf
2019-04-12 10:57                                     ` Kevin Wolf
2019-04-15  2:39                                     ` [Qemu-arm] " Xiang Zheng
2019-04-15  2:39                                       ` Xiang Zheng
2019-04-15  2:39                                       ` Xiang Zheng
2019-04-22  1:37                                       ` [Qemu-arm] " Xiang Zheng
2019-04-22  1:37                                         ` Xiang Zheng
2019-04-22  1:37                                         ` Xiang Zheng
2019-03-25 14:07   ` Laszlo Ersek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.