From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: patches@linaro.org, Paolo Bonzini <pbonzini@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Marcel Apfelbaum <marcel@redhat.com>
Subject: [Qemu-devel] [PATCH 2/3] memory.h: Add new utility function memory_region_allocate_aux_memory()
Date: Tue, 4 Jul 2017 18:02:42 +0100 [thread overview]
Message-ID: <1499187763-8211-3-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1499187763-8211-1-git-send-email-peter.maydell@linaro.org>
Add a new utility function memory_region_allocate_aux_memory()
for board code to use to create auxiliary memory regions (such
as display RAM or static RAMs). This parallels the existing
memory_region_allocate_system_memory() and wraps up the very
common sequence of:
memory_region_init_ram(sram, NULL, "sram", 0x10000, &error_fatal);
vmstate_register_ram_global(sram);
Although this is the parallel function to the existing
memory_region_allocate_system_memory(), we don't put it in
boards.h/numa.c with it because this function is useful for
devices, not just boards, and it has nothing to do with NUMA.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/exec/memory.h | 23 +++++++++++++++++++++++
include/hw/boards.h | 3 ++-
memory.c | 8 ++++++++
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 8503685..77fc777 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -412,6 +412,12 @@ void memory_region_init_io(MemoryRegion *mr,
* must be unique within any device
* @size: size of the region.
* @errp: pointer to Error*, to store an error if it happens.
+ *
+ * Note that it is the caller's responsibility to ensure that the contents
+ * of the RAM are migrated (by calling vmstate_register_ram_global(), or
+ * otherwise). The utility function memory_region_allocate_aux_memory()
+ * may be used to combine the "initialize MR" and "register contents for
+ * migration" steps.
*/
void memory_region_init_ram(MemoryRegion *mr,
struct Object *owner,
@@ -631,6 +637,23 @@ void memory_region_init_iommu(MemoryRegion *mr,
uint64_t size);
/**
+ * memory_region_allocate_aux_memory - Allocate auxiliary (non-main) memory
+ * @mr: the #MemoryRegion to be initialized
+ * @owner: the object that tracks the region's reference count
+ * @name: name of the memory region
+ * @ram_size: size of the region in bytes
+ *
+ * This function allocates RAM for a board model or device, and
+ * arranges for it to be migrated (by calling vmstate_register_ram_global()).
+ * Board models should call memory_region_allocate_system_memory()
+ * exactly once to allocate the memory for the primary or largest RAM
+ * area on the board, and then can use this function for smaller
+ * pieces of memory such as display RAM or static RAMs.
+ */
+void memory_region_allocate_aux_memory(MemoryRegion *mr, Object *owner,
+ const char *name, uint64_t ram_size);
+
+/**
* memory_region_owner: get a memory region's owner.
*
* @mr: the memory region being queried.
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 1bc5389..a127a97 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -35,7 +35,8 @@
*
* Smaller pieces of memory (display RAM, static RAMs, etc) don't need
* to be backed via the -mem-path memory backend and can simply
- * be created via memory_region_init_ram().
+ * be created via memory_region_allocate_aux_memory() or
+ * memory_region_init_ram().
*/
void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
const char *name,
diff --git a/memory.c b/memory.c
index 1044bba..25ac7d7 100644
--- a/memory.c
+++ b/memory.c
@@ -32,6 +32,7 @@
#include "sysemu/sysemu.h"
#include "hw/misc/mmio_interface.h"
#include "hw/qdev-properties.h"
+#include "migration/vmstate.h"
//#define DEBUG_UNASSIGNED
@@ -2817,6 +2818,13 @@ void mtree_info(fprintf_function mon_printf, void *f, bool flatview)
}
}
+void memory_region_allocate_aux_memory(MemoryRegion *mr, Object *owner,
+ const char *name, uint64_t ram_size)
+{
+ memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
+ vmstate_register_ram_global(mr);
+}
+
static const TypeInfo memory_region_info = {
.parent = TYPE_OBJECT,
.name = TYPE_MEMORY_REGION,
--
2.7.4
next prev parent reply other threads:[~2017-07-04 17:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-04 17:02 [Qemu-devel] [PATCH 0/3] Add new utility function memory_region_allocate_aux_memory() Peter Maydell
2017-07-04 17:02 ` [Qemu-devel] [PATCH 1/3] include/hw/boards.h: Document memory_region_allocate_system_memory() Peter Maydell
2017-07-06 3:18 ` Philippe Mathieu-Daudé
2017-07-06 8:46 ` Paolo Bonzini
2017-07-04 17:02 ` Peter Maydell [this message]
2017-07-04 17:02 ` [Qemu-devel] [PATCH 3/3] hw: Use new memory_region_allocate_aux_memory() function Peter Maydell
2017-07-05 12:21 ` [Qemu-devel] [PATCH 0/3] Add new utility function memory_region_allocate_aux_memory() Paolo Bonzini
2017-07-06 14:52 ` Peter Maydell
2017-07-06 14:56 ` Paolo Bonzini
2017-07-06 16:26 ` Peter Maydell
2017-07-06 16:49 ` Paolo Bonzini
2017-07-07 13:18 ` Igor Mammedov
2017-07-07 13:49 ` Peter Maydell
2017-07-17 16:28 ` Peter Maydell
2017-07-07 13:06 ` Igor Mammedov
2017-07-06 17:13 ` Peter Maydell
2017-07-06 17:26 ` Paolo Bonzini
2017-07-06 17:47 ` Peter Maydell
2017-07-07 10:43 ` Peter Maydell
2017-07-07 10:55 ` Paolo Bonzini
2017-07-07 11:58 ` Peter Maydell
2017-07-07 12:03 ` Paolo Bonzini
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=1499187763-8211-3-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=ehabkost@redhat.com \
--cc=marcel@redhat.com \
--cc=patches@linaro.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).