From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org,
"Igor Mammedov" <imammedo@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Xiao Guangrong" <xiaoguangrong.eric@gmail.com>,
"David Hildenbrand" <david@redhat.com>,
"Cédric Le Goater" <clg@kaod.org>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Greg Kurz" <groug@kaod.org>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Song Gao" <gaosong@loongson.cn>,
"Xiaojuan Yang" <yangxiaojuan@loongson.cn>
Subject: [PATCH v4 02/10] memory-device: Introduce machine_memory_devices_init()
Date: Fri, 23 Jun 2023 14:45:45 +0200 [thread overview]
Message-ID: <20230623124553.400585-3-david@redhat.com> (raw)
In-Reply-To: <20230623124553.400585-1-david@redhat.com>
Let's intrduce a new helper that we will use to replace existing memory
device setup code during machine initialization. We'll enforce that the
size has to be > 0.
Once all machines were converted, we'll only allocate ms->device_memory
if the size > 0.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/mem/memory-device.c | 14 ++++++++++++++
include/hw/boards.h | 2 ++
2 files changed, 16 insertions(+)
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 49f86ec8a8..bb9d7c2a20 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -17,6 +17,7 @@
#include "qemu/range.h"
#include "hw/virtio/vhost.h"
#include "sysemu/kvm.h"
+#include "exec/address-spaces.h"
#include "trace.h"
static gint memory_device_addr_sort(gconstpointer a, gconstpointer b)
@@ -328,6 +329,19 @@ uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
return memory_region_size(mr);
}
+void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size)
+{
+ g_assert(size);
+ g_assert(!ms->device_memory);
+ ms->device_memory = g_new0(DeviceMemoryState, 1);
+ ms->device_memory->base = base;
+
+ memory_region_init(&ms->device_memory->mr, OBJECT(ms), "device-memory",
+ size);
+ memory_region_add_subregion(get_system_memory(), ms->device_memory->base,
+ &ms->device_memory->mr);
+}
+
static const TypeInfo memory_device_info = {
.name = TYPE_MEMORY_DEVICE,
.parent = TYPE_INTERFACE,
diff --git a/include/hw/boards.h b/include/hw/boards.h
index a385010909..be06e8a41f 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -35,6 +35,8 @@ void machine_set_cpu_numa_node(MachineState *machine,
Error **errp);
void machine_parse_smp_config(MachineState *ms,
const SMPConfiguration *config, Error **errp);
+void machine_memory_devices_init(MachineState *ms, hwaddr base, uint64_t size);
+
/**
* machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
--
2.40.1
next prev parent reply other threads:[~2023-06-23 12:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-23 12:45 [PATCH v4 00/10] memory-device: Some cleanups David Hildenbrand
2023-06-23 12:45 ` [PATCH v4 01/10] memory-device: Unify enabled vs. supported error messages David Hildenbrand
2023-06-23 12:45 ` David Hildenbrand [this message]
2023-06-23 12:45 ` [PATCH v4 03/10] hw/arm/virt: Use machine_memory_devices_init() David Hildenbrand
2023-06-23 12:45 ` [PATCH v4 04/10] hw/ppc/spapr: " David Hildenbrand
2023-06-23 12:45 ` [PATCH v4 05/10] hw/loongarch/virt: " David Hildenbrand
2023-06-23 12:45 ` [PATCH v4 06/10] hw/i386/pc: " David Hildenbrand
2023-06-23 12:45 ` [PATCH v4 07/10] hw/i386/acpi-build: Rely on machine->device_memory when building SRAT David Hildenbrand
2023-06-23 12:45 ` [PATCH v4 08/10] hw/i386/pc: Remove PC_MACHINE_DEVMEM_REGION_SIZE David Hildenbrand
2023-06-23 12:45 ` [PATCH v4 09/10] memory-device: Refactor memory_device_pre_plug() David Hildenbrand
2023-06-23 12:45 ` [PATCH v4 10/10] memory-device: Track used region size in DeviceMemoryState David Hildenbrand
2023-06-27 12:24 ` [PATCH v4 00/10] memory-device: Some cleanups David Hildenbrand
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=20230623124553.400585-3-david@redhat.com \
--to=david@redhat.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=eduardo@habkost.net \
--cc=gaosong@loongson.cn \
--cc=groug@kaod.org \
--cc=harshpb@linux.ibm.com \
--cc=imammedo@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=xiaoguangrong.eric@gmail.com \
--cc=yangxiaojuan@loongson.cn \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).