[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/35] dimm: add busy slot check and slot auto-alloc
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 18/35] dimm: add busy slot check and slot auto-allocation |
Date: |
Fri, 4 Apr 2014 15:36:43 +0200 |
- if slot property is not specified on -device/device_add command,
treat default value as request for assigning DimmDevice 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 <address@hidden>
---
hw/i386/pc.c | 15 +++++++++++++++
hw/mem/dimm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
include/hw/mem/dimm.h | 2 ++
3 files changed, 64 insertions(+)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 29382ec..e3e63bb 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1489,6 +1489,8 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
DimmDeviceClass *ddc = DIMM_GET_CLASS(dimm);
MemoryRegion *mr = ddc->get_memory_region(dimm);
ram_addr_t addr = dimm->start;
+ MachineState *machine = MACHINE(hotplug_dev);
+ int slot = dimm->slot;
addr = dimm_get_free_addr(pcms->hotplug_memory_base,
memory_region_size(&pcms->hotplug_memory),
@@ -1498,6 +1500,19 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
goto out;
}
object_property_set_int(OBJECT(dev), addr, "start", &local_err);
+ if (local_err) {
+ goto out;
+ }
+
+ slot = dimm_get_free_slot(slot < 0 ? NULL : &slot,
+ machine->init_args.ram_slots, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ object_property_set_int(OBJECT(dev), slot, "slot", &local_err);
+ if (local_err) {
+ goto out;
+ }
memory_region_add_subregion(&pcms->hotplug_memory,
addr - pcms->hotplug_memory_base,
diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index a10bd07..16fdf62 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -23,6 +23,53 @@
#include "qapi/visitor.h"
#include "qemu/range.h"
+static int dimm_slot2bitmap(Object *obj, void *opaque)
+{
+ unsigned long *bitmap = opaque;
+
+ if (object_dynamic_cast(obj, TYPE_DIMM)) {
+ DeviceState *dev = DEVICE(obj);
+ if (dev->realized) { /* count only realized DIMMs */
+ DimmDevice *d = DIMM(obj);
+ set_bit(d->slot, bitmap);
+ }
+ }
+
+ object_child_foreach(obj, dimm_slot2bitmap, opaque);
+ return 0;
+}
+
+int 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(), 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);
+ }
+ 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 dimm_addr_sort(gconstpointer a, gconstpointer b)
{
DimmDevice *x = DIMM(a);
diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h
index d6e4d65..fa27208 100644
--- a/include/hw/mem/dimm.h
+++ b/include/hw/mem/dimm.h
@@ -67,4 +67,6 @@ uint64_t dimm_get_free_addr(uint64_t address_space_start,
uint64_t address_space_size,
uint64_t *hint, uint64_t size,
Error **errp);
+
+int dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
#endif
--
1.9.0
- [Qemu-devel] [PATCH 12/35] dimm: do not allow to set already busy memdev, (continued)
- [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, 2014/04/04
- [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 <=
- [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
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Michael S. Tsirkin, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Igor Mammedov, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Michael S. Tsirkin, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Igor Mammedov, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Michael S. Tsirkin, 2014/04/07
- Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic, Igor Mammedov, 2014/04/07