aboutsummaryrefslogtreecommitdiff
path: root/hw/mem
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2014-06-02 15:25:14 +0200
committerMichael S. Tsirkin <mst@redhat.com>2014-06-19 16:41:49 +0300
commit0cd03d89b98154fcc03d9a8eeea70b9c50cb9457 (patch)
tree0b49df52f1d3c7a81fb4d7bc94fdc6e06b686dfe /hw/mem
parent0b3125711606374f04e279aebefcb7275480f040 (diff)
downloadqemu-0cd03d89b98154fcc03d9a8eeea70b9c50cb9457.zip
qemu-0cd03d89b98154fcc03d9a8eeea70b9c50cb9457.tar.gz
qemu-0cd03d89b98154fcc03d9a8eeea70b9c50cb9457.tar.bz2
pc-dimm: add busy slot check and slot auto-allocation
- if slot property is not specified on -device/device_add command, treat default value as request for assigning PCDIMMDevice to the first free slot. - if slot is provided with -device/device_add command, attempt to use it or fail command if it's already occupied. Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/mem')
-rw-r--r--hw/mem/pc-dimm.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 40b51c8..8c26568 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -23,6 +23,52 @@
#include "qapi/visitor.h"
#include "qemu/range.h"
+static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
+{
+ unsigned long *bitmap = opaque;
+
+ if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+ DeviceState *dev = DEVICE(obj);
+ if (dev->realized) { /* count only realized DIMMs */
+ PCDIMMDevice *d = PC_DIMM(obj);
+ set_bit(d->slot, bitmap);
+ }
+ }
+
+ object_child_foreach(obj, pc_dimm_slot2bitmap, opaque);
+ return 0;
+}
+
+int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp)
+{
+ unsigned long *bitmap = bitmap_new(max_slots);
+ int slot = 0;
+
+ object_child_foreach(qdev_get_machine(), pc_dimm_slot2bitmap, bitmap);
+
+ /* check if requested slot is not occupied */
+ if (hint) {
+ if (*hint >= max_slots) {
+ error_setg(errp, "invalid slot# %d, should be less than %d",
+ *hint, max_slots);
+ } else if (!test_bit(*hint, bitmap)) {
+ slot = *hint;
+ } else {
+ error_setg(errp, "slot %d is busy", *hint);
+ }
+ goto out;
+ }
+
+ /* search for free slot */
+ slot = find_first_zero_bit(bitmap, max_slots);
+ if (slot == max_slots) {
+ error_setg(errp, "no free slots available");
+ }
+out:
+ g_free(bitmap);
+ return slot;
+}
+
static gint pc_dimm_addr_sort(gconstpointer a, gconstpointer b)
{
PCDIMMDevice *x = PC_DIMM(a);