qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 07/16] dimm: map DimmDevice into DimBus provided add


From: Igor Mammedov
Subject: [Qemu-devel] [PATCH 07/16] dimm: map DimmDevice into DimBus provided address space
Date: Tue, 23 Jul 2013 18:23:03 +0200

Signed-off-by: Igor Mammedov <address@hidden>
---
 hw/mem-hotplug/dimm.c         |   14 ++++++++++++++
 include/hw/mem-hotplug/dimm.h |   14 ++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/hw/mem-hotplug/dimm.c b/hw/mem-hotplug/dimm.c
index 0a337a5..63c2c8e 100644
--- a/hw/mem-hotplug/dimm.c
+++ b/hw/mem-hotplug/dimm.c
@@ -27,14 +27,23 @@ static void dimm_bus_initfn(Object *obj)
 
     b->allow_hotplug = true;
 }
+static void dimm_bus_register_memory(DimmBus *bus, DimmDevice *dimm,
+                                     Error **errp)
+{
+    memory_region_add_subregion(&bus->as, dimm->start - bus->base, &dimm->mr);
+    vmstate_register_ram_global(&dimm->mr);
+}
+
 static void dimm_bus_class_init(ObjectClass *klass, void *data)
 {
     BusClass *bc = BUS_CLASS(klass);
+    DimmBusClass *dc = DIMM_BUS_CLASS(klass);
     QemuOpts *opts = qemu_opts_find(qemu_find_opts("memory-opts"), NULL);
 
     if (opts) {
         bc->max_dev = qemu_opt_get_number(opts, "slots", 0);
     }
+    dc->register_memory = dimm_bus_register_memory;
 }
 
 static const TypeInfo dimm_bus_info = {
@@ -43,6 +52,7 @@ static const TypeInfo dimm_bus_info = {
     .instance_init = dimm_bus_initfn,
     .instance_size = sizeof(DimmBus),
     .class_init = dimm_bus_class_init,
+    .class_size = sizeof(DimmBusClass),
 };
 
 static Property dimm_properties[] = {
@@ -58,6 +68,7 @@ static void dimm_realize(DeviceState *dev, Error **errp)
     DimmDevice *dimm = DIMM(dev);
     DimmBus *bus = DIMM_BUS(qdev_get_parent_bus(dev));
     BusClass *bc = BUS_GET_CLASS(bus);
+    DimmBusClass *dc = DIMM_BUS_GET_CLASS(bus);
 
     if (!dev->id) {
         error_setg(errp, "missing 'id' property");
@@ -70,6 +81,9 @@ static void dimm_realize(DeviceState *dev, Error **errp)
     }
 
     memory_region_init_ram(&dimm->mr, dev->id, dimm->size);
+
+    g_assert(dc->register_memory);
+    dc->register_memory(bus, dimm, errp);
 }
 
 static void dimm_class_init(ObjectClass *klass, void *data)
diff --git a/include/hw/mem-hotplug/dimm.h b/include/hw/mem-hotplug/dimm.h
index c83ad26..84d6ba6 100644
--- a/include/hw/mem-hotplug/dimm.h
+++ b/include/hw/mem-hotplug/dimm.h
@@ -58,9 +58,23 @@ typedef struct DimmDeviceClass {
 
 /**
  * DimmBus:
+ * @base: address from which to start mapping @DimmDevice
+ * @as: hot-plugabble memory area where @DimmDevice-s are attached
  */
 typedef struct DimmBus {
     BusState qbus;
+    hwaddr base;
+    MemoryRegion as;
 } DimmBus;
 
+/**
+ * DimmBusClass:
+ * @register_memory: map @DimmDevice into hot-plugable address space
+ */
+typedef struct DimmBusClass {
+    BusClass parent_class;
+
+    void (*register_memory)(DimmBus *bus, DimmDevice *dimm, Error **errp);
+} DimmBusClass;
+
 #endif
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]