[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 018/103] pc-dimm: add busy slot check and slot auto-a
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 018/103] pc-dimm: add busy slot check and slot auto-allocation |
Date: |
Tue, 17 Jun 2014 20:37:20 +0300 |
From: Igor Mammedov <address@hidden>
- 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 <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/hw/mem/pc-dimm.h | 2 ++
hw/i386/pc.c | 21 +++++++++++++++++++++
hw/mem/pc-dimm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+)
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 5cd8f35..5f80d14 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -74,4 +74,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
uint64_t address_space_size,
uint64_t *hint, uint64_t size,
Error **errp);
+
+int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
#endif
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 8cd8fcb..ece551d 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1551,8 +1551,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);
PCDIMMDevice *dimm = PC_DIMM(dev);
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
MemoryRegion *mr = ddc->get_memory_region(dimm);
@@ -1569,7 +1571,26 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
if (local_err) {
goto out;
}
+
object_property_set_int(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_err);
+ if (local_err) {
+ goto out;
+ }
+
+ slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err);
+ if (local_err) {
+ goto out;
+ }
+
+ slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL :
&slot,
+ machine->ram_slots, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ object_property_set_int(OBJECT(dev), slot, PC_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/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);
--
MST
- [Qemu-devel] [PULL 007/103] qdev: hotplug for buss-less devices, (continued)
- [Qemu-devel] [PULL 007/103] qdev: hotplug for buss-less devices, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 002/103] pc: ACPI BIOS: use enum for defining memory affinity flags, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 008/103] qdev: expose DeviceState.hotplugged field as a property, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 011/103] pc-dimm: do not allow to set already used memdev, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 010/103] memory: add memory_region_is_mapped() API, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 009/103] pc: implement pc-dimm device abstraction, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 014/103] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 015/103] pc: exit QEMU if compat machine doesn't support memory hotlpug, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 013/103] pc: exit QEMU if number of slots more than supported 256, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 017/103] pc-dimm: add busy address check and address auto-allocation, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 018/103] pc-dimm: add busy slot check and slot auto-allocation,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 019/103] acpi: rename cpu_hotplug_defs.h to pc-hotplug.h, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 020/103] acpi: memory hotplug ACPI hardware implementation, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 021/103] trace: add acpi memory hotplug IO region events, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 022/103] trace: pc: add PC_DIMM slot & address allocation, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 012/103] pc: initialize memory hotplug address space, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 024/103] acpi:piix4: add memory hotplug handling, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 023/103] acpi:piix4: allow plug/unlug callbacks handle not only PCI devices, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 025/103] pc: ich9 lpc: make it work with global/compat properties, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 016/103] pc: add memory hotplug handler to PC_MACHINE, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 026/103] acpi:ich9: add memory hotplug handling, Michael S. Tsirkin, 2014/06/17