From: Stefano Stabellini <sstabellini@kernel.org>
To: peter.maydell@linaro.org
Cc: sstabellini@kernel.org, richard.henderson@linaro.org,
qemu-devel@nongnu.org, vikram.garhwal@amd.com,
Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
Stefano Stabellini <stefano.stabellini@amd.com>
Subject: [PULL v2 2/2] xen_arm: Initialize RAM and add hi/low memory regions
Date: Wed, 30 Aug 2023 18:27:31 -0700 [thread overview]
Message-ID: <20230831012731.525739-2-sstabellini@kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2308301824340.6458@ubuntu-linux-20-04-desktop>
From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
In order to use virtio backends we need to initialize RAM for the
xen-mapcache (which is responsible for mapping guest memory using foreign
mapping) to work. Calculate and add hi/low memory regions based on
machine->ram_size.
Use the constants defined in public header arch-arm.h to be aligned with the xen
toolstack.
While using this machine, the toolstack should then pass real ram_size using
"-m" arg. If "-m" is not given, create a QEMU machine without IOREQ and other
emulated devices like TPM and VIRTIO. This is done to keep this QEMU machine
usable for /etc/init.d/xencommons.
Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
hw/arm/xen_arm.c | 45 +++++++++++++++++++++++++++++++++++++
include/hw/xen/xen_native.h | 8 +++++++
2 files changed, 53 insertions(+)
diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
index 7393b37355..f83b983ec5 100644
--- a/hw/arm/xen_arm.c
+++ b/hw/arm/xen_arm.c
@@ -60,6 +60,8 @@ struct XenArmState {
} cfg;
};
+static MemoryRegion ram_lo, ram_hi;
+
/*
* VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen
* repository.
@@ -92,6 +94,39 @@ static void xen_create_virtio_mmio_devices(XenArmState *xam)
}
}
+static void xen_init_ram(MachineState *machine)
+{
+ MemoryRegion *sysmem = get_system_memory();
+ ram_addr_t block_len, ram_size[GUEST_RAM_BANKS];
+
+ if (machine->ram_size <= GUEST_RAM0_SIZE) {
+ ram_size[0] = machine->ram_size;
+ ram_size[1] = 0;
+ block_len = GUEST_RAM0_BASE + ram_size[0];
+ } else {
+ ram_size[0] = GUEST_RAM0_SIZE;
+ ram_size[1] = machine->ram_size - GUEST_RAM0_SIZE;
+ block_len = GUEST_RAM1_BASE + ram_size[1];
+ }
+
+ memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len,
+ &error_fatal);
+
+ memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo", &ram_memory,
+ GUEST_RAM0_BASE, ram_size[0]);
+ memory_region_add_subregion(sysmem, GUEST_RAM0_BASE, &ram_lo);
+ DPRINTF("Initialized region xen.ram.lo: base 0x%llx size 0x%lx\n",
+ GUEST_RAM0_BASE, ram_size[0]);
+
+ if (ram_size[1] > 0) {
+ memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi", &ram_memory,
+ GUEST_RAM1_BASE, ram_size[1]);
+ memory_region_add_subregion(sysmem, GUEST_RAM1_BASE, &ram_hi);
+ DPRINTF("Initialized region xen.ram.hi: base 0x%llx size 0x%lx\n",
+ GUEST_RAM1_BASE, ram_size[1]);
+ }
+}
+
void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
{
hw_error("Invalid ioreq type 0x%x\n", req->type);
@@ -141,6 +176,14 @@ static void xen_arm_init(MachineState *machine)
xam->state = g_new0(XenIOState, 1);
+ if (machine->ram_size == 0) {
+ DPRINTF("ram_size not specified. QEMU machine started without IOREQ"
+ "(no emulated devices including Virtio)\n");
+ return;
+ }
+
+ xen_init_ram(machine);
+
xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener);
xen_create_virtio_mmio_devices(xam);
@@ -188,6 +231,8 @@ static void xen_arm_machine_class_init(ObjectClass *oc, void *data)
mc->init = xen_arm_init;
mc->max_cpus = 1;
mc->default_machine_opts = "accel=xen";
+ /* Set explicitly here to make sure that real ram_size is passed */
+ mc->default_ram_size = 0;
#ifdef CONFIG_TPM
object_class_property_add(oc, "tpm-base-addr", "uint64_t",
diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h
index a4b1aa9e5d..5d2718261f 100644
--- a/include/hw/xen/xen_native.h
+++ b/include/hw/xen/xen_native.h
@@ -539,4 +539,12 @@ static inline int xendevicemodel_set_irq_level(xendevicemodel_handle *dmod,
#define GUEST_VIRTIO_MMIO_SPI_LAST 43
#endif
+#if defined(__i386__) || defined(__x86_64__)
+#define GUEST_RAM_BANKS 2
+#define GUEST_RAM0_BASE 0x40000000ULL /* 3GB of low RAM @ 1GB */
+#define GUEST_RAM0_SIZE 0xc0000000ULL
+#define GUEST_RAM1_BASE 0x0200000000ULL /* 1016GB of RAM @ 8GB */
+#define GUEST_RAM1_SIZE 0xfe00000000ULL
+#endif
+
#endif /* QEMU_HW_XEN_NATIVE_H */
--
2.25.1
next prev parent reply other threads:[~2023-08-31 1:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 1:27 [PULL v2 0/2] xen-virtio-2-tag Stefano Stabellini
2023-08-31 1:27 ` [PULL v2 1/2] xen_arm: Create virtio-mmio devices during initialization Stefano Stabellini
2023-08-31 1:27 ` Stefano Stabellini [this message]
2023-08-31 16:14 ` [PULL v2 0/2] xen-virtio-2-tag Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230831012731.525739-2-sstabellini@kernel.org \
--to=sstabellini@kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=stefano.stabellini@amd.com \
--cc=vikram.garhwal@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.