memory-device: complete factoring out plug handling

With the new memory device functions in place, we can factor out
plugging of memory devices completely.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20181005092024.14344-15-david@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
David Hildenbrand 2018-10-05 11:20:22 +02:00 committed by Eduardo Habkost
parent 6ef2c0f2c1
commit 55d67a0492
3 changed files with 12 additions and 13 deletions

View File

@ -273,10 +273,17 @@ out:
error_propagate(errp, local_err); error_propagate(errp, local_err);
} }
void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, void memory_device_plug(MemoryDeviceState *md, MachineState *ms)
uint64_t addr)
{ {
/* we expect a previous call to memory_device_get_free_addr() */ const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
const uint64_t addr = mdc->get_addr(md);
MemoryRegion *mr;
/*
* We expect that a previous call to memory_device_pre_plug() succeeded, so
* it can't fail at this point.
*/
mr = mdc->get_memory_region(md, &error_abort);
g_assert(ms->device_memory); g_assert(ms->device_memory);
memory_region_add_subregion(&ms->device_memory->mr, memory_region_add_subregion(&ms->device_memory->mr,

View File

@ -63,17 +63,10 @@ out:
void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp) void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
{ {
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm, MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
&error_abort); &error_abort);
MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
&error_abort);
uint64_t addr;
addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP, memory_device_plug(MEMORY_DEVICE(dimm), machine);
&error_abort);
memory_device_plug_region(machine, mr, addr);
vmstate_register_ram(vmstate_mr, DEVICE(dimm)); vmstate_register_ram(vmstate_mr, DEVICE(dimm));
} }

View File

@ -101,8 +101,7 @@ MemoryDeviceInfoList *qmp_memory_device_list(void);
uint64_t get_plugged_memory_size(void); uint64_t get_plugged_memory_size(void);
void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
const uint64_t *legacy_align, Error **errp); const uint64_t *legacy_align, Error **errp);
void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
uint64_t addr);
void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
uint64_t memory_device_get_region_size(const MemoryDeviceState *md, uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
Error **errp); Error **errp);