Skip to content

Commit

Permalink
memory-device: Introduce machine_memory_devices_init()
Browse files Browse the repository at this point in the history
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>
Message-Id: <20230623124553.400585-3-david@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
  • Loading branch information
davidhildenbrand committed Jul 12, 2023
1 parent 99d88de commit cc0afd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions hw/mem/memory-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions include/hw/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void machine_parse_smp_config(MachineState *ms,
const SMPConfiguration *config, Error **errp);
unsigned int machine_topo_get_cores_per_socket(const MachineState *ms);
unsigned int machine_topo_get_threads_per_socket(const MachineState *ms);
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
Expand Down

0 comments on commit cc0afd8

Please sign in to comment.