[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 11/27] dimm: add busy address check and address auto
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 11/27] dimm: add busy address check and address auto-allocation |
Date: |
Thu, 21 Nov 2013 03:38:32 +0100 |
- 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>
---
v2:
* s/dc/dbc/
* if DimmBus is not initialized, report error "memory add is disabled"
---
hw/mem/dimm.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
include/hw/mem/dimm.h | 5 +++
2 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c
index 8837ffe..b3c27cc 100644
--- a/hw/mem/dimm.c
+++ b/hw/mem/dimm.c
@@ -22,6 +22,7 @@
#include "qemu/config-file.h"
#include "qapi/visitor.h"
#include "qemu/bitmap.h"
+#include "qemu/range.h"
static void dimm_bus_initfn(Object *obj)
{
@@ -68,6 +69,70 @@ out:
return slot;
}
+static gint dimm_bus_addr_sort(gconstpointer a, gconstpointer b)
+{
+ DimmDevice *x = DIMM(a);
+ DimmDevice *y = DIMM(b);
+
+ return x->start - y->start;
+}
+
+static int dimm_bus_built_dimm_list(DeviceState *dev, void *opaque)
+{
+ GSList **list = opaque;
+
+ if (dev->realized) { /* only realized DIMMs matter */
+ *list = g_slist_insert_sorted(*list, dev, dimm_bus_addr_sort);
+ }
+ return 0;
+}
+
+static hwaddr dimm_bus_get_free_addr(DimmBus *bus, const hwaddr *hint,
+ uint64_t size, Error **errp)
+{
+ GSList *list = NULL, *item;
+ hwaddr new_start, ret;
+ uint64_t as_size;
+
+ if (!bus->base) {
+ error_setg(errp, "adding memory to '%s' is disabled", BUS(bus)->name);
+ return 0;
+ }
+
+ qbus_walk_children(BUS(bus), dimm_bus_built_dimm_list, NULL, &list);
+
+ if (hint) {
+ new_start = *hint;
+ } else {
+ new_start = bus->base;
+ }
+
+ /* find address range that will fit new DIMM */
+ for (item = list; item; item = g_slist_next(item)) {
+ DimmDevice *dimm = item->data;
+ if (ranges_overlap(dimm->start, memory_region_size(dimm->mr),
+ new_start, size)) {
+ if (hint) {
+ DeviceState *d = DEVICE(dimm);
+ error_setg(errp, "address range conflicts with '%s'", d->id);
+ break;
+ }
+ new_start = dimm->start + memory_region_size(dimm->mr);
+ }
+ }
+ ret = new_start;
+
+ g_slist_free(list);
+
+ as_size = memory_region_size(&bus->as);
+ if ((new_start + size) > (bus->base + as_size)) {
+ error_setg(errp, "can't add memory beyond 0x%" PRIx64,
+ bus->base + as_size);
+ }
+
+ return ret;
+}
+
static void dimm_bus_register_memory(DimmBus *bus, DimmDevice *dimm,
Error **errp)
{
@@ -84,6 +149,7 @@ static void dimm_bus_class_init(ObjectClass *oc, void *data)
bc->max_dev = qemu_opt_get_number(opts, "slots", 0);
dbc->register_memory = dimm_bus_register_memory;
dbc->get_free_slot = dimm_bus_get_free_slot;
+ dbc->get_free_addr = dimm_bus_get_free_addr;
}
static const TypeInfo dimm_bus_info = {
@@ -174,6 +240,7 @@ static void dimm_realize(DeviceState *dev, Error **errp)
BusClass *bc = BUS_GET_CLASS(bus);
DimmBusClass *dbc = DIMM_BUS_GET_CLASS(bus);
int *slot_hint;
+ hwaddr *start_hint;
if (!dimm->mr) {
error_setg(errp, "'memdev' property is not set");
@@ -196,6 +263,18 @@ static void dimm_realize(DeviceState *dev, Error **errp)
return;
}
+ start_hint = !dimm->start ? NULL : &dimm->start;
+ if (start_hint && (dimm->start < bus->base)) {
+ error_setg(errp, "can't map DIMM below: 0x%" PRIx64, bus->base);
+ return;
+ }
+
+ g_assert(dbc->get_free_addr);
+ dimm->start = dbc->get_free_addr(bus, start_hint,
+ memory_region_size(dimm->mr), errp);
+ if (error_is_set(errp)) {
+ return;
+ }
g_assert(dbc->register_memory);
dbc->register_memory(bus, dimm, errp);
diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h
index 963b26d..abedae2 100644
--- a/include/hw/mem/dimm.h
+++ b/include/hw/mem/dimm.h
@@ -78,6 +78,9 @@ typedef struct DimmBus {
* @get_free_slot: returns a not occupied slot number. If @hint is provided,
* it tries to return slot specified by @hint if it's not busy or returns
* error in @errp.
+ * @get_free_addr: returns address where @DimmDevice of specified size
+ * might be mapped. If @hint is specified it returns hinted address if
+ * region is available or error in @errp.
* @register_memory: map @DimmDevice into hot-plugable address space
*/
typedef struct DimmBusClass {
@@ -85,6 +88,8 @@ typedef struct DimmBusClass {
int (*get_free_slot)(DimmBus *bus, const int *hint, Error **errp);
void (*register_memory)(DimmBus *bus, DimmDevice *dimm, Error **errp);
+ hwaddr (*get_free_addr)(DimmBus *bus, const hwaddr *hint,
+ uint64_t size, Error **errp);
} DimmBusClass;
#endif
--
1.7.1
- Re: [Qemu-devel] [PATCH 02/27] rename pci_hotplug_fn to hotplug_fn and make it available for other devices, (continued)
- [Qemu-devel] [PATCH 05/27] qapi: add SIZE type parser to string_input_visitor, Igor Mammedov, 2013/11/20
- [Qemu-devel] [PATCH 06/27] get reference to /backend container via qemu_get_backend(), Igor Mammedov, 2013/11/20
- [Qemu-devel] [PATCH 07/27] add memdev backend infrastructure, Igor Mammedov, 2013/11/20
- [Qemu-devel] [PATCH 08/27] dimm: implement dimm device abstraction, Igor Mammedov, 2013/11/20
- [Qemu-devel] [PATCH 09/27] dimm: map DimmDevice into DimBus provided address space, Igor Mammedov, 2013/11/20
- [Qemu-devel] [PATCH 10/27] dimm: add busy slot check and slot auto-allocation, Igor Mammedov, 2013/11/20
- [Qemu-devel] [PATCH 11/27] dimm: add busy address check and address auto-allocation,
Igor Mammedov <=
- [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Igor Mammedov, 2013/11/20
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Michael S. Tsirkin, 2013/11/21
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Igor Mammedov, 2013/11/21
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Michael S. Tsirkin, 2013/11/21
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Igor Mammedov, 2013/11/22
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Michael S. Tsirkin, 2013/11/24
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Markus Armbruster, 2013/11/25
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Paolo Bonzini, 2013/11/25
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Igor Mammedov, 2013/11/25
- Re: [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation, Paolo Bonzini, 2013/11/25