From: Eduardo Habkost <ehabkost@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Alexander Graf <agraf@suse.de>, Rob Herring <robh@kernel.org>,
libvir-list@redhat.com, Richard Henderson <rth@twiddle.net>,
David Gibson <david@gibson.dropbear.id.au>,
Eric Blake <eblake@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
qemu-arm@nongnu.org,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Markus Armbruster <armbru@redhat.com>,
Artyom Tarasenko <atar4qemu@gmail.com>,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
Eduardo Habkost <ehabkost@redhat.com>,
Michael Walle <michael@walle.cc>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Aleksandar Markovic <amarkovic@wavecomp.com>,
Aurelien Jarno <aurelien@aurel32.net>,
Alistair Francis <alistair@alistair23.me>,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
qemu-ppc@nongnu.org,
Xiao Guangrong <xiaoguangrong.eric@gmail.com>,
Max Filippov <jcmvbkbc@gmail.com>,
David Hildenbrand <david@redhat.com>
Subject: [Qemu-devel] [PULL 27/45] memory-device: factor out get_memory_region() from pc-dimm
Date: Thu, 18 Oct 2018 17:04:04 -0300 [thread overview]
Message-ID: <20181018200422.4358-28-ehabkost@redhat.com> (raw)
In-Reply-To: <20181018200422.4358-1-ehabkost@redhat.com>
From: David Hildenbrand <david@redhat.com>
The memory region is necessary for plugging/unplugging a memory device.
The region size (via get_region_size()) is no longer sufficient, as
besides the alignment, also the region itself is required in order to
add it to the device memory region of the machine via
- memory_region_add_subregion
- memory_region_del_subregion
So, to factor out plugging/unplugging of memory devices from pc-dimm
code, we have to factor out access to the memory region first.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20181005092024.14344-11-david@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
include/hw/mem/memory-device.h | 15 +++++++++++++++
include/hw/mem/pc-dimm.h | 4 ----
hw/mem/nvdimm.c | 9 ++++++---
hw/mem/pc-dimm.c | 27 ++++++++++++++++++---------
4 files changed, 39 insertions(+), 16 deletions(-)
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 898df3057d..659f38385c 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -38,6 +38,11 @@ typedef struct MemoryDeviceState {
* mapped into guest physical address space at a certain address. The
* address in guest physical memory can either be specified explicitly
* or get assigned automatically.
+ *
+ * Conceptually, memory devices only span one memory region. If multiple
+ * successive memory regions are used, a covering memory region has to
+ * be provided. Scattered memory regions are not supported for single
+ * devices.
*/
typedef struct MemoryDeviceClass {
/* private */
@@ -68,6 +73,16 @@ typedef struct MemoryDeviceClass {
uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
+ /*
+ * Return the memory region of the memory device.
+ *
+ * Called when (un)plugging the memory device, to (un)map the
+ * memory region in guest physical memory, but also to detect the
+ * required alignment during address assignment or when the size of the
+ * memory region is required.
+ */
+ MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp);
+
/*
* Translate the memory device into #MemoryDeviceInfo.
*/
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 99cbd54de7..01436b9f50 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -61,9 +61,6 @@ typedef struct PCDIMMDevice {
* PCDIMMDeviceClass:
* @realize: called after common dimm is realized so that the dimm based
* devices get the chance to do specified operations.
- * @get_memory_region: returns #MemoryRegion associated with @dimm which
- * is directly mapped into the physical address space of guest. Will not
- * fail after the device was realized.
* @get_vmstate_memory_region: returns #MemoryRegion which indicates the
* memory of @dimm should be kept during live migration. Will not fail
* after the device was realized.
@@ -74,7 +71,6 @@ typedef struct PCDIMMDeviceClass {
/* public */
void (*realize)(PCDIMMDevice *dimm, Error **errp);
- MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp);
MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm,
Error **errp);
} PCDIMMDeviceClass;
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index 1c6674c4ed..49324f3fae 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -27,6 +27,7 @@
#include "qapi/error.h"
#include "qapi/visitor.h"
#include "hw/mem/nvdimm.h"
+#include "hw/mem/memory-device.h"
static void nvdimm_get_label_size(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
@@ -118,9 +119,10 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice *nvdimm, Error **errp)
nvdimm->nvdimm_mr->align = align;
}
-static MemoryRegion *nvdimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)
+static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md,
+ Error **errp)
{
- NVDIMMDevice *nvdimm = NVDIMM(dimm);
+ NVDIMMDevice *nvdimm = NVDIMM(md);
Error *local_err = NULL;
if (!nvdimm->nvdimm_mr) {
@@ -190,11 +192,12 @@ static Property nvdimm_properties[] = {
static void nvdimm_class_init(ObjectClass *oc, void *data)
{
PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
+ MemoryDeviceClass *mdc = MEMORY_DEVICE_CLASS(oc);
NVDIMMClass *nvc = NVDIMM_CLASS(oc);
DeviceClass *dc = DEVICE_CLASS(oc);
ddc->realize = nvdimm_realize;
- ddc->get_memory_region = nvdimm_get_memory_region;
+ mdc->get_memory_region = nvdimm_md_get_memory_region;
dc->props = nvdimm_properties;
nvc->read_label_data = nvdimm_read_label_data;
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 3e43ec8742..c9f6ad589e 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -32,7 +32,7 @@ static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
const uint64_t *legacy_align, Error **errp)
{
- PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+ MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
Error *local_err = NULL;
MemoryRegion *mr;
uint64_t addr, align;
@@ -49,7 +49,7 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
&error_abort);
trace_mhp_pc_dimm_assigned_slot(slot);
- mr = ddc->get_memory_region(dimm, &local_err);
+ mr = mdc->get_memory_region(MEMORY_DEVICE(dimm), &local_err);
if (local_err) {
goto out;
}
@@ -72,9 +72,11 @@ out:
void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
{
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+ MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
&error_abort);
- MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
+ MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
+ &error_abort);
uint64_t addr;
addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
@@ -87,9 +89,11 @@ void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine)
{
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+ MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
&error_abort);
- MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort);
+ MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
+ &error_abort);
memory_device_unplug_region(machine, mr);
vmstate_unregister_ram(vmstate_mr, DEVICE(dimm));
@@ -235,12 +239,11 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
Error **errp)
{
- /* dropping const here is fine as we don't touch the memory region */
- PCDIMMDevice *dimm = PC_DIMM(md);
- const PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(md);
+ MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
MemoryRegion *mr;
- mr = ddc->get_memory_region(dimm, errp);
+ /* dropping const here is fine as we don't touch the memory region */
+ mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
if (!mr) {
return 0;
}
@@ -248,6 +251,12 @@ static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
return memory_region_size(mr);
}
+static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
+ Error **errp)
+{
+ return pc_dimm_get_memory_region(PC_DIMM(md), errp);
+}
+
static void pc_dimm_md_fill_device_info(const MemoryDeviceState *md,
MemoryDeviceInfo *info)
{
@@ -289,13 +298,13 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
dc->props = pc_dimm_properties;
dc->desc = "DIMM memory module";
- ddc->get_memory_region = pc_dimm_get_memory_region;
ddc->get_vmstate_memory_region = pc_dimm_get_memory_region;
mdc->get_addr = pc_dimm_md_get_addr;
/* for a dimm plugged_size == region_size */
mdc->get_plugged_size = pc_dimm_md_get_region_size;
mdc->get_region_size = pc_dimm_md_get_region_size;
+ mdc->get_memory_region = pc_dimm_md_get_memory_region;
mdc->fill_device_info = pc_dimm_md_fill_device_info;
}
--
2.18.0.rc1.1.g3f1ff2140
next prev parent reply other threads:[~2018-10-18 20:08 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-18 20:03 [Qemu-devel] [PULL 00/45] Machine queue, 2018-10-18 Eduardo Habkost
2018-10-18 20:03 ` [Qemu-devel] [PULL 01/45] hostmem-file: fixed the memory leak while get pmem path Eduardo Habkost
2018-10-21 17:37 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 02/45] vl.c deprecate incorrect CPUs topology Eduardo Habkost
2018-10-21 17:38 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 03/45] vl:c: make sure that sockets are calculated correctly in '-smp X' case Eduardo Habkost
2018-10-23 15:06 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 04/45] numa: Fix QMP command set-numa-node error handling Eduardo Habkost
2018-10-23 15:07 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 05/45] trace-events: Fix copy/paste typo Eduardo Habkost
2018-10-23 15:08 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 06/45] hw/timer/sun4v-rtc: Convert from DPRINTF() macro to trace events Eduardo Habkost
2018-10-23 15:09 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 07/45] hw/timer/sun4v-rtc: Use DeviceState::realize rather than SysBusDevice::init Eduardo Habkost
2018-10-23 15:10 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 08/45] hw/ssi/xilinx_spi: " Eduardo Habkost
2018-10-23 15:11 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 09/45] hw/sh4/sh_pci: " Eduardo Habkost
2018-10-23 15:12 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 10/45] hw/pci-host/bonito: " Eduardo Habkost
2018-10-23 15:14 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 11/45] hw/mips/gt64xxx_pci: Convert gt64120_reset() function into Device reset method Eduardo Habkost
2018-10-18 20:03 ` [Qemu-devel] [PULL 12/45] hw/mips/gt64xxx_pci: Mark as bridge device Eduardo Habkost
2018-10-23 15:16 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 13/45] hw/sparc64/niagara: Model the I/O Bridge with the 'unimplemented_device' Eduardo Habkost
2018-10-18 20:03 ` [Qemu-devel] [PULL 14/45] hw/alpha/typhoon: Remove unuseful code Eduardo Habkost
2018-10-23 15:18 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 15/45] hw/hppa/dino: " Eduardo Habkost
2018-10-23 15:18 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 16/45] hw/mips/malta: " Eduardo Habkost
2018-10-23 15:19 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 17/45] machine: fix a typo Eduardo Habkost
2018-10-23 15:20 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 18/45] memory-device: fix alignment error message Eduardo Habkost
2018-10-23 15:20 ` David Gibson
2018-10-18 20:03 ` [Qemu-devel] [PULL 19/45] memory-device: fix error message when hinted address is too small Eduardo Habkost
2018-10-18 20:03 ` [Qemu-devel] [PULL 20/45] memory-device: improve "range conflicts" error message Eduardo Habkost
2018-10-18 20:03 ` [Qemu-devel] [PULL 21/45] pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug Eduardo Habkost
2018-10-18 20:03 ` [Qemu-devel] [PULL 22/45] memory-device: use memory device terminology in error messages Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 23/45] memory-device: introduce separate config option Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 24/45] memory-device: forward errors in get_region_size()/get_plugged_size() Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 25/45] memory-device: document MemoryDeviceClass Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 26/45] memory-device: add and use memory_device_get_region_size() Eduardo Habkost
2018-10-18 20:04 ` Eduardo Habkost [this message]
2018-10-18 20:04 ` [Qemu-devel] [PULL 28/45] memory-device: drop get_region_size() Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 29/45] memory-device: add device class function set_addr() Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 30/45] memory-device: complete factoring out pre_plug handling Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 31/45] memory-device: complete factoring out plug handling Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 32/45] memory-device: complete factoring out unplug handling Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 33/45] memory-device: trace when pre_plugging/plugging/unplugging Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 34/45] net: etraxfs_eth: convert SysBus init method to a realize method Eduardo Habkost
2018-10-23 15:22 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 35/45] net: etraxfs_eth: add a reset method Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 36/45] net: lan9118: convert SysBus init method to a realize method Eduardo Habkost
2018-10-23 15:23 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 37/45] net: lance: " Eduardo Habkost
2018-10-23 15:24 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 38/45] net: milkymist_minimac2: " Eduardo Habkost
2018-10-23 15:24 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 39/45] net: mipsnet: " Eduardo Habkost
2018-10-23 15:25 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 40/45] net: opencores_eth: " Eduardo Habkost
2018-10-23 15:25 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 41/45] net: smc91c111: " Eduardo Habkost
2018-10-23 15:25 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 42/45] net: stellaris_enet: " Eduardo Habkost
2018-10-23 15:26 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 43/45] net: stellaris_enet: add a reset method Eduardo Habkost
2018-10-18 20:04 ` [Qemu-devel] [PULL 44/45] net: xgmac: convert SysBus init method to a realize method Eduardo Habkost
2018-10-23 15:26 ` David Gibson
2018-10-18 20:04 ` [Qemu-devel] [PULL 45/45] numa: Clean up error reporting in parse_numa() Eduardo Habkost
2018-10-23 15:27 ` David Gibson
2018-10-19 14:12 ` [Qemu-devel] [PULL 00/45] Machine queue, 2018-10-18 Peter Maydell
2018-10-19 17:00 ` Philippe Mathieu-Daudé
2018-10-19 17:55 ` Philippe Mathieu-Daudé
2018-10-19 18:44 ` Eduardo Habkost
2018-10-19 19:53 ` Igor Mammedov
2018-10-19 20:23 ` Eduardo Habkost
2018-10-20 10:27 ` Philippe Mathieu-Daudé
2018-10-22 9:00 ` Igor Mammedov
2018-10-22 15:02 ` Markus Armbruster
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=20181018200422.4358-28-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=agraf@suse.de \
--cc=alistair@alistair23.me \
--cc=amarkovic@wavecomp.com \
--cc=armbru@redhat.com \
--cc=atar4qemu@gmail.com \
--cc=aurelien@aurel32.net \
--cc=crosthwaite.peter@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=eblake@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=imammedo@redhat.com \
--cc=jasowang@redhat.com \
--cc=jcmvbkbc@gmail.com \
--cc=libvir-list@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=michael@walle.cc \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=robh@kernel.org \
--cc=rth@twiddle.net \
--cc=xiaoguangrong.eric@gmail.com \
/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).