diff mbox series

[RFC,2/4] mem: implement memory_device_set_region_size

Message ID 154943076146.27958.8619995020189724984.stgit@lep8c.aus.stglabs.ibm.com (mailing list archive)
State New, archived
Headers show
Series ppc: spapr: virtual NVDIMM support | expand

Commit Message

Shivaprasad G Bhat Feb. 6, 2019, 5:26 a.m. UTC
Required for PAPR NVDIMM implementation. Need memory_device_set_region_size
for aligning the size to the SCM block size.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
---
 hw/mem/memory-device.c         |   15 +++++++++++++++
 include/hw/mem/memory-device.h |    2 ++
 2 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 5f2c408036..ad0419e203 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -330,6 +330,21 @@  uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
     return memory_region_size(mr);
 }
 
+void memory_device_set_region_size(const MemoryDeviceState *md,
+                                   uint64_t size, Error **errp)
+{
+    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    MemoryRegion *mr;
+
+    /* dropping const here is fine as we don't touch the memory region */
+    mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
+    if (!mr) {
+        return;
+    }
+
+    memory_region_set_size(mr, size);
+}
+
 static const TypeInfo memory_device_info = {
     .name          = TYPE_MEMORY_DEVICE,
     .parent        = TYPE_INTERFACE,
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 0293a96abb..ba9b72fd28 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -103,5 +103,7 @@  void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
 void memory_device_unplug(MemoryDeviceState *md, MachineState *ms);
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
                                        Error **errp);
+void memory_device_set_region_size(const MemoryDeviceState *md,
+                                   uint64_t size, Error **errp);
 
 #endif