[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 02/10] memory-device: Introduce machine_memory_devices_init()
From: |
David Hildenbrand |
Subject: |
[PATCH v3 02/10] memory-device: Introduce machine_memory_devices_init() |
Date: |
Thu, 1 Jun 2023 14:14:39 +0200 |
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
- [PATCH] memory-device: Track used region size in DeviceMemoryState, David Hildenbrand, 2023/06/01
- [PATCH v3 00/10] memory-device: Some cleanups, David Hildenbrand, 2023/06/01
- [PATCH v3 02/10] memory-device: Introduce machine_memory_devices_init(),
David Hildenbrand <=
- [PATCH v3 03/10] hw/arm/virt: Use machine_memory_devices_init(), David Hildenbrand, 2023/06/01
- [PATCH v3 04/10] hw/ppc/spapr: Use machine_memory_devices_init(), David Hildenbrand, 2023/06/01
- [PATCH v3 01/10] memory-device: Unify enabled vs. supported error messages, David Hildenbrand, 2023/06/01
- [PATCH v3 05/10] hw/loongarch/virt: Use machine_memory_devices_init(), David Hildenbrand, 2023/06/01
- [PATCH v3 06/10] hw/i386/pc: Use machine_memory_devices_init(), David Hildenbrand, 2023/06/01
- [PATCH v3 07/10] hw/i386/acpi-build: Rely on machine->device_memory when building SRAT, David Hildenbrand, 2023/06/01
- [PATCH v3 10/10] memory-device: Track used region size in DeviceMemoryState, David Hildenbrand, 2023/06/01
- [PATCH v3 08/10] hw/i386/pc: Remove PC_MACHINE_DEVMEM_REGION_SIZE, David Hildenbrand, 2023/06/01
- [PATCH v3 09/10] memory-device: Refactor memory_device_pre_plug(), David Hildenbrand, 2023/06/01