summaryrefslogtreecommitdiffstats
path: root/hw/core/machine.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/core/machine.c')
-rw-r--r--hw/core/machine.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 1a6e485c87..c8d361b710 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -26,6 +26,7 @@
#include "sysemu/qtest.h"
#include "hw/pci/pci.h"
#include "hw/mem/nvdimm.h"
+#include "migration/vmstate.h"
GlobalProperty hw_compat_4_2[] = {
{ "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
@@ -1059,10 +1060,33 @@ static void machine_numa_finish_cpu_init(MachineState *machine)
g_string_free(s, true);
}
+MemoryRegion *machine_consume_memdev(MachineState *machine,
+ HostMemoryBackend *backend)
+{
+ MemoryRegion *ret = host_memory_backend_get_memory(backend);
+
+ if (memory_region_is_mapped(ret)) {
+ char *path = object_get_canonical_path_component(OBJECT(backend));
+ error_report("memory backend %s can't be used multiple times.", path);
+ g_free(path);
+ exit(EXIT_FAILURE);
+ }
+ host_memory_backend_set_mapped(backend, true);
+ vmstate_register_ram_global(ret);
+ return ret;
+}
+
void machine_run_board_init(MachineState *machine)
{
MachineClass *machine_class = MACHINE_GET_CLASS(machine);
+ if (machine->ram_memdev_id) {
+ Object *o;
+ o = object_resolve_path_type(machine->ram_memdev_id,
+ TYPE_MEMORY_BACKEND, NULL);
+ machine->ram = machine_consume_memdev(machine, MEMORY_BACKEND(o));
+ }
+
if (machine->numa_state) {
numa_complete_configuration(machine);
if (machine->numa_state->num_nodes) {