pc_existing_dimms_capacity() can be static since it is not used out of pc-dimm.c and drop the pc_ prefix to prepare the work which abstracts dimm device type from pc-dimm Signed-off-by: Xiao Guangrong <guangrong.xiao@xxxxxxxxxxxxxxx> --- hw/mem/pc-dimm.c | 73 ++++++++++++++++++++++++------------------------ include/hw/mem/pc-dimm.h | 1 - 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 2bae994..425f627 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -32,6 +32,38 @@ typedef struct pc_dimms_capacity { Error **errp; } pc_dimms_capacity; +static int existing_dimms_capacity_internal(Object *obj, void *opaque) +{ + pc_dimms_capacity *cap = opaque; + uint64_t *size = &cap->size; + + if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { + DeviceState *dev = DEVICE(obj); + + if (dev->realized) { + (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, + cap->errp); + } + + if (cap->errp && *cap->errp) { + return 1; + } + } + object_child_foreach(obj, existing_dimms_capacity_internal, opaque); + return 0; +} + +static uint64_t existing_dimms_capacity(Error **errp) +{ + pc_dimms_capacity cap; + + cap.size = 0; + cap.errp = errp; + + existing_dimms_capacity_internal(qdev_get_machine(), &cap); + return cap.size; +} + void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, MemoryRegion *mr, uint64_t align, bool gap, Error **errp) @@ -40,7 +72,7 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, MachineState *machine = MACHINE(qdev_get_machine()); PCDIMMDevice *dimm = PC_DIMM(dev); Error *local_err = NULL; - uint64_t existing_dimms_capacity = 0; + uint64_t dimms_capacity = 0; uint64_t addr; addr = object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &local_err); @@ -56,17 +88,16 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, goto out; } - existing_dimms_capacity = pc_existing_dimms_capacity(&local_err); + dimms_capacity = existing_dimms_capacity(&local_err); if (local_err) { goto out; } - if (existing_dimms_capacity + memory_region_size(mr) > + if (dimms_capacity + memory_region_size(mr) > machine->maxram_size - machine->ram_size) { error_setg(&local_err, "not enough space, currently 0x%" PRIx64 " in use of total hot pluggable 0x" RAM_ADDR_FMT, - existing_dimms_capacity, - machine->maxram_size - machine->ram_size); + dimms_capacity, machine->maxram_size - machine->ram_size); goto out; } @@ -121,38 +152,6 @@ void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms, vmstate_unregister_ram(mr, dev); } -static int pc_existing_dimms_capacity_internal(Object *obj, void *opaque) -{ - pc_dimms_capacity *cap = opaque; - uint64_t *size = &cap->size; - - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { - DeviceState *dev = DEVICE(obj); - - if (dev->realized) { - (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, - cap->errp); - } - - if (cap->errp && *cap->errp) { - return 1; - } - } - object_child_foreach(obj, pc_existing_dimms_capacity_internal, opaque); - return 0; -} - -uint64_t pc_existing_dimms_capacity(Error **errp) -{ - pc_dimms_capacity cap; - - cap.size = 0; - cap.errp = errp; - - pc_existing_dimms_capacity_internal(qdev_get_machine(), &cap); - return cap.size; -} - int qmp_pc_dimm_device_list(Object *obj, void *opaque) { MemoryDeviceInfoList ***prev = opaque; diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 15590f1..c1e5774 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -87,7 +87,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); int qmp_pc_dimm_device_list(Object *obj, void *opaque); -uint64_t pc_existing_dimms_capacity(Error **errp); void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, MemoryRegion *mr, uint64_t align, bool gap, Error **errp); -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html