[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 17/31] dimm: add busy slot check and slot auto-al
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH v2 17/31] dimm: add busy slot check and slot auto-allocation |
Date: |
Tue, 20 May 2014 17:15:20 +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 | 21 +++++++++++++++++++++
hw/mem/dimm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
include/hw/mem/dimm.h | 2 ++
3 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 42f41df..aee8dfb 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1541,8 +1541,10 @@ void qemu_register_pc_machine(QEMUMachine *m)
static void pc_dimm_plug(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
+ int slot;
Error *local_err = NULL;
PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+ MachineState *machine = MACHINE(hotplug_dev);
DimmDevice *dimm = DIMM(dev);
DimmDeviceClass *ddc = DIMM_GET_CLASS(dimm);
MemoryRegion *mr = ddc->get_memory_region(dimm);
@@ -1559,7 +1561,26 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
if (local_err) {
goto out;
}
+
object_property_set_int(OBJECT(dev), addr, DIMM_ADDR_PROP, &local_err);
+ if (local_err) {
+ goto out;
+ }
+
+ slot = object_property_get_int(OBJECT(dev), DIMM_SLOT_PROP, &local_err);
+ if (local_err) {
+ goto out;
+ }
+
+ slot = dimm_get_free_slot(slot == DIMM_UNASSIGNED_SLOT ? NULL : &slot,
+ machine->ram_slots, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ object_property_set_int(OBJECT(dev), slot, DIMM_SLOT_PROP, &local_err);
+ if (local_err) {
+ goto out;
+ }
memory_region_add_subregion(&pcms->hotplug_memory,
addr - pcms->hotplug_memory_base, mr);
diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index 1c726c6..a189b59 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -23,6 +23,52 @@
#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);
+ } 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 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 55bdfb2..1be8fb2 100644
--- a/include/hw/mem/dimm.h
+++ b/include/hw/mem/dimm.h
@@ -75,4 +75,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.7.1
- [Qemu-devel] [PATCH v2 05/31] vl.c: extend -m option to support options for memory hotplug, (continued)
- [Qemu-devel] [PATCH v2 05/31] vl.c: extend -m option to support options for memory hotplug, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 07/31] qdev: hotplug for buss-less devices, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 08/31] qdev: expose DeviceState.hotplugged field as a property, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 09/31] dimm: implement dimm device abstraction, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 10/31] memory: add memory_region_is_mapped() API, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 11/31] dimm: do not allow to set already used memdev, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 13/31] pc: exit QEMU if number of slots more than supported 256, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 14/31] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 15/31] pc: add memory hotplug handler to PC_MACHINE, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 16/31] dimm: add busy address check and address auto-allocation, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 17/31] dimm: add busy slot check and slot auto-allocation,
Igor Mammedov <=
- [Qemu-devel] [PATCH v2 18/31] acpi: rename cpu_hotplug_defs.h to acpi_defs.h, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 19/31] acpi: memory hotplug ACPI hardware implementation, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 21/31] trace: pc: add DIMM slot & address allocation, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 24/31] pc: ich9 lpc: make it work with global/compat properties, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 29/31] pc: ACPI BIOS: implement memory hotplug interface, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 31/31] pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 20/31] trace: add acpi memory hotplug IO region events, Igor Mammedov, 2014/05/20
- [Qemu-devel] [PATCH v2 12/31] pc: initialize memory hotplug address space, Igor Mammedov, 2014/05/20