[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 17/35] dimm: add busy address check and address auto
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 17/35] dimm: add busy address check and address auto-allocation |
Date: |
Fri, 4 Apr 2014 15:36:42 +0200 |
- if 'start' property is not specified on -device/device_add command,
treat default value as request for assigning DimmDevice to
the first free memory region.
- if 'start' is provided with -device/device_add command, attempt to
use it or fail command if it's already occupied or falls inside
of an existing DimmDevice memory region.
Signed-off-by: Igor Mammedov <address@hidden>
---
hw/i386/pc.c | 16 +++++++++++-
hw/mem/dimm.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++
include/hw/mem/dimm.h | 5 ++++
3 files changed, 89 insertions(+), 1 deletion(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4038e2c..29382ec 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1483,15 +1483,29 @@ void qemu_register_pc_machine(QEMUMachine *m)
static void pc_dimm_plug(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
+ Error *local_err = NULL;
PCMachineState *pcms = PC_MACHINE(hotplug_dev);
DimmDevice *dimm = DIMM(dev);
DimmDeviceClass *ddc = DIMM_GET_CLASS(dimm);
MemoryRegion *mr = ddc->get_memory_region(dimm);
+ ram_addr_t addr = dimm->start;
+
+ addr = dimm_get_free_addr(pcms->hotplug_memory_base,
+ memory_region_size(&pcms->hotplug_memory),
+ !addr ? NULL : &addr,
+ memory_region_size(mr), &local_err);
+ if (local_err) {
+ goto out;
+ }
+ object_property_set_int(OBJECT(dev), addr, "start", &local_err);
memory_region_add_subregion(&pcms->hotplug_memory,
- dimm->start - pcms->hotplug_memory_base,
+ addr - pcms->hotplug_memory_base,
mr);
vmstate_register_ram(mr, dev);
+
+out:
+ error_propagate(errp, local_err);
}
static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,
diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index 65d4cd0..a10bd07 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -21,6 +21,75 @@
#include "hw/mem/dimm.h"
#include "qemu/config-file.h"
#include "qapi/visitor.h"
+#include "qemu/range.h"
+
+static gint dimm_addr_sort(gconstpointer a, gconstpointer b)
+{
+ DimmDevice *x = DIMM(a);
+ DimmDevice *y = DIMM(b);
+
+ return x->start - y->start;
+}
+
+static int dimm_built_list(Object *obj, void *opaque)
+{
+ GSList **list = opaque;
+
+ if (object_dynamic_cast(obj, TYPE_DIMM)) {
+ DeviceState *dev = DEVICE(obj);
+ if (dev->realized) { /* only realized DIMMs matter */
+ *list = g_slist_insert_sorted(*list, dev, dimm_addr_sort);
+ }
+ }
+
+ object_child_foreach(obj, dimm_built_list, opaque);
+ return 0;
+}
+
+uint64_t dimm_get_free_addr(uint64_t address_space_start,
+ uint64_t address_space_size,
+ uint64_t *hint, uint64_t size,
+ Error **errp)
+{
+ GSList *list = NULL, *item;
+ uint64_t new_start, ret;
+ uint64_t address_space_end = address_space_start + address_space_size;
+
+ object_child_foreach(qdev_get_machine(), dimm_built_list, &list);
+
+ if (hint) {
+ new_start = *hint;
+ } else {
+ new_start = address_space_start;
+ }
+
+ /* find address range that will fit new DIMM */
+ for (item = list; item; item = g_slist_next(item)) {
+ DimmDevice *dimm = item->data;
+ uint64_t dimm_size = object_property_get_int(OBJECT(dimm),
+ "size", &error_abort);
+ if (ranges_overlap(dimm->start, dimm_size, new_start, size)) {
+ if (hint) {
+ DeviceState *d = DEVICE(dimm);
+ error_setg(errp, "address range conflicts with '%s'", d->id);
+ break;
+ }
+ new_start = dimm->start + dimm_size;
+ }
+ }
+ ret = new_start;
+
+ g_slist_free(list);
+
+ if (new_start < address_space_start) {
+ error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
+ "] at 0x%" PRIx64, new_start, size, address_space_start);
+ } else if ((new_start + size) > address_space_end) {
+ error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
+ "] beyond 0x%" PRIx64, new_start, size, address_space_end);
+ }
+ return ret;
+}
static Property dimm_properties[] = {
DEFINE_PROP_UINT64("start", DimmDevice, start, 0),
diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h
index 4bbf0ed..d6e4d65 100644
--- a/include/hw/mem/dimm.h
+++ b/include/hw/mem/dimm.h
@@ -62,4 +62,9 @@ typedef struct DimmDeviceClass {
MemoryRegion *(*get_memory_region)(DimmDevice *dimm);
} DimmDeviceClass;
+
+uint64_t dimm_get_free_addr(uint64_t address_space_start,
+ uint64_t address_space_size,
+ uint64_t *hint, uint64_t size,
+ Error **errp);
#endif
--
1.9.0
- Re: [Qemu-devel] [PATCH 08/35] qdev: hotplug for buss-less devices, (continued)
- [Qemu-devel] [PATCH 09/35] qdev: expose DeviceState.hotplugged field as a property, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 12/35] dimm: do not allow to set already busy memdev, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 11/35] memory: add memory_region_is_mapped() API, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 02/35] vl: convert -m to QemuOpts, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 13/35] pc: initialize memory hotplug address space, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 14/35] pc: exit QEMU if slots > 256, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 15/35] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 17/35] dimm: add busy address check and address auto-allocation,
Igor Mammedov <=
- [Qemu-devel] [PATCH 07/35] pc: create custom generic PC machine type, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 18/35] dimm: add busy slot check and slot auto-allocation, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 20/35] acpi: memory hotplug ACPI hardware implementation, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 10/35] dimm: implement dimm device abstraction, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 19/35] acpi: rename cpu_hotplug_defs.h to acpi_defs.h, Igor Mammedov, 2014/04/04
- [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Igor Mammedov, 2014/04/04