qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, Eduardo Habkost <ehabkost@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	David Gibson <david@gibson.dropbear.id.au>,
	Alexander Graf <agraf@suse.de>,
	David Hildenbrand <david@redhat.com>
Subject: [Qemu-devel] [PATCH v1 3/4] pc-dimm/memory-device: detect alignment internally
Date: Mon, 18 Jun 2018 16:47:59 +0200	[thread overview]
Message-ID: <20180618144800.555-4-david@redhat.com> (raw)
In-Reply-To: <20180618144800.555-1-david@redhat.com>

We can now avoid having to pass in the alignment explicitly but can
instead make use of the new machine compat parameter
"memory_device_align".

As we are using TARGET_PAGE_SIZE in memory-device.c, we can now longer
compile it as common object.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/i386/pc.c                   | 13 +------------
 hw/mem/Makefile.objs           |  2 +-
 hw/mem/memory-device.c         | 25 +++++++++++++++++++++++++
 hw/mem/pc-dimm.c               |  4 ++--
 hw/ppc/spapr.c                 |  5 ++---
 include/hw/mem/memory-device.h |  1 +
 include/hw/mem/pc-dimm.h       |  3 +--
 7 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 04a97e89e7..d5581ab0a1 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1704,20 +1704,9 @@ static void pc_memory_plug(HotplugHandler *hotplug_dev,
     HotplugHandlerClass *hhc;
     Error *local_err = NULL;
     PCMachineState *pcms = PC_MACHINE(hotplug_dev);
-    MachineClass *mc = MACHINE_GET_CLASS(hotplug_dev);
-    PCDIMMDevice *dimm = PC_DIMM(dev);
-    PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-    MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
-    uint64_t align = TARGET_PAGE_SIZE;
     bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
 
-
-    if (memory_region_get_alignment(mr) &&
-        mc->memory_device_align != MEMORY_DEVICE_ALIGN_PAGE) {
-        align = memory_region_get_alignment(mr);
-    }
-
-    pc_dimm_plug(dev, MACHINE(pcms), align, &local_err);
+    pc_dimm_plug(dev, MACHINE(pcms), &local_err);
     if (local_err) {
         goto out;
     }
diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs
index 10be4df2a2..f519441091 100644
--- a/hw/mem/Makefile.objs
+++ b/hw/mem/Makefile.objs
@@ -1,3 +1,3 @@
 common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o
-common-obj-$(CONFIG_MEM_HOTPLUG) += memory-device.o
+obj-$(CONFIG_MEM_HOTPLUG) += memory-device.o
 common-obj-$(CONFIG_NVDIMM) += nvdimm.o
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 6de4f70bb4..968c64be97 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -249,6 +249,31 @@ uint64_t get_plugged_memory_size(void)
     return size;
 }
 
+uint64_t memory_device_get_align(MachineState *ms, MemoryRegion *mr) {
+    const MachineClass *mc = MACHINE_GET_CLASS(ms);
+    uint64_t align;
+
+    /* use the configured memory device alignment (compat handling) */
+    switch (mc->memory_device_align) {
+    case MEMORY_DEVICE_ALIGN_REGION:
+        align = memory_region_get_alignment(mr);;
+        break;
+    case MEMORY_DEVICE_ALIGN_PAGE:
+        align = TARGET_PAGE_SIZE;
+        break;
+    case MEMORY_DEVICE_ALIGN_REGION_OR_PAGE:
+        align = memory_region_get_alignment(mr);
+        if (!align) {
+            align = TARGET_PAGE_SIZE;
+        }
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    return align;
+}
+
 void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
                                uint64_t addr)
 {
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index e56c4daef2..9198104d34 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -47,14 +47,14 @@ out:
     error_propagate(errp, local_err);
 }
 
-void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align,
-                  Error **errp)
+void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp)
 {
     PCDIMMDevice *dimm = PC_DIMM(dev);
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
     MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
                                                               &error_abort);
     MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
+    const uint64_t align = memory_device_get_align(machine, mr);
     Error *local_err = NULL;
     uint64_t addr;
 
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 9da233588b..03752c6aaf 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3143,13 +3143,12 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     PCDIMMDevice *dimm = PC_DIMM(dev);
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
     MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
-    uint64_t align, size, addr;
+    uint64_t size, addr;
     uint32_t node;
 
-    align = memory_region_get_alignment(mr);
     size = memory_region_size(mr);
 
-    pc_dimm_plug(dev, MACHINE(ms), align, &local_err);
+    pc_dimm_plug(dev, MACHINE(ms), &local_err);
     if (local_err) {
         goto out;
     }
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 2853b084b5..32cd15a0cb 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -44,6 +44,7 @@ uint64_t get_plugged_memory_size(void);
 uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
                                      uint64_t align, uint64_t size,
                                      Error **errp);
+uint64_t memory_device_get_align(MachineState *ms, MemoryRegion *mr);
 void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
                                uint64_t addr);
 void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 7b120416d1..ba9f7e7146 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -80,7 +80,6 @@ typedef struct PCDIMMDeviceClass {
 } PCDIMMDeviceClass;
 
 void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, Error **errp);
-void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align,
-                  Error **errp);
+void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp);
 void pc_dimm_unplug(DeviceState *dev, MachineState *machine);
 #endif
-- 
2.17.1

  parent reply	other threads:[~2018-06-18 14:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-18 14:47 [Qemu-devel] [PATCH v1 0/4] pc-dimm: pre_plug "slot" and "addr" assignment David Hildenbrand
2018-06-18 14:47 ` [Qemu-devel] [PATCH v1 1/4] pc-dimm: assign and verify the "slot" property during pre_plug David Hildenbrand
2018-06-19  0:14   ` David Gibson
2018-06-19 15:48   ` Igor Mammedov
2018-06-18 14:47 ` [Qemu-devel] [PATCH v1 2/4] machine: factor out enforce_aligned_dimm into memory_device_align David Hildenbrand
2018-06-19 15:59   ` Igor Mammedov
2018-06-19 17:06     ` David Hildenbrand
2018-06-20 14:58       ` David Hildenbrand
2018-06-26 15:03       ` Igor Mammedov
2018-06-28 10:41         ` David Hildenbrand
2018-06-18 14:47 ` David Hildenbrand [this message]
2018-06-18 14:48 ` [Qemu-devel] [PATCH v1 4/4] pc-dimm: assign and verify the "addr" property during pre_plug David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180618144800.555-4-david@redhat.com \
    --to=david@redhat.com \
    --cc=agraf@suse.de \
    --cc=david@gibson.dropbear.id.au \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).