aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
Diffstat (limited to 'hw')
-rw-r--r--hw/mem/memory-device.c18
-rw-r--r--hw/mem/pc-dimm.c5
2 files changed, 20 insertions, 3 deletions
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 8535ddc..3e04f39 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -243,6 +243,24 @@ uint64_t get_plugged_memory_size(void)
return size;
}
+void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
+ uint64_t addr)
+{
+ /* we expect a previous call to memory_device_get_free_addr() */
+ g_assert(ms->device_memory);
+
+ memory_region_add_subregion(&ms->device_memory->mr,
+ addr - ms->device_memory->base, mr);
+}
+
+void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr)
+{
+ /* we expect a previous call to memory_device_get_free_addr() */
+ g_assert(ms->device_memory);
+
+ memory_region_del_subregion(&ms->device_memory->mr, mr);
+}
+
static const TypeInfo memory_device_info = {
.name = TYPE_MEMORY_DEVICE,
.parent = TYPE_INTERFACE,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 8aa2d36..0119c68 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -36,7 +36,6 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine,
uint64_t align, Error **errp)
{
int slot;
- MemoryHotplugState *hpms = machine->device_memory;
PCDIMMDevice *dimm = PC_DIMM(dev);
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm);
@@ -83,7 +82,7 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine,
}
trace_mhp_pc_dimm_assigned_slot(slot);
- memory_region_add_subregion(&hpms->mr, addr - hpms->base, mr);
+ memory_device_plug_region(machine, mr, addr);
vmstate_register_ram(vmstate_mr, dev);
out:
@@ -97,7 +96,7 @@ void pc_dimm_memory_unplug(DeviceState *dev, MachineState *machine)
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm);
MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
- memory_region_del_subregion(&machine->device_memory->mr, mr);
+ memory_device_unplug_region(machine, mr);
vmstate_unregister_ram(vmstate_mr, dev);
}