From patchwork Mon Oct 10 00:34:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9368841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 29D026048F for ; Mon, 10 Oct 2016 00:39:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F31428B40 for ; Mon, 10 Oct 2016 00:39:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1401028B4C; Mon, 10 Oct 2016 00:39:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 66CA528B4B for ; Mon, 10 Oct 2016 00:39:51 +0000 (UTC) Received: from localhost ([::1]:46612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOdC-0001CN-G9 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 09 Oct 2016 20:39:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOYs-0006Ja-K3 for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btOYp-0003Lq-AX for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:22 -0400 Received: from mga07.intel.com ([134.134.136.100]:26495) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOYo-0003Ld-VG for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:19 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP; 09 Oct 2016 17:35:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,469,1473145200"; d="scan'208"; a="1051561142" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.148]) by fmsmga001.fm.intel.com with ESMTP; 09 Oct 2016 17:35:16 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xensource.com Date: Mon, 10 Oct 2016 08:34:23 +0800 Message-Id: <20161010003423.4333-9-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161010003423.4333-1-haozhong.zhang@intel.com> References: <20161010003423.4333-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.100 Subject: [Qemu-devel] [RFC QEMU PATCH 8/8] qmp: add a qmp command 'query-nvdimms' to get plugged NVDIMM devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Xiao Guangrong , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Markus Armbruster , Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Xen uses this command to get the backend resource, guest SPA and size of NVDIMM devices so as to map them to guest. Signed-off-by: Haozhong Zhang --- Cc: Markus Armbruster Cc: Xiao Guangrong Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Eric Blake --- docs/qmp-commands.txt | 36 ++++++++++++++++++++++++++++++++++++ hw/acpi/nvdimm.c | 2 +- hw/mem/nvdimm.c | 35 +++++++++++++++++++++++++++++++++++ include/hw/mem/nvdimm.h | 10 ++++++++++ qapi-schema.json | 29 +++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) diff --git a/docs/qmp-commands.txt b/docs/qmp-commands.txt index e0adceb..90e9fb6 100644 --- a/docs/qmp-commands.txt +++ b/docs/qmp-commands.txt @@ -3800,3 +3800,39 @@ Example for pc machine type started with "props": {"core-id": 0, "socket-id": 0, "thread-id": 0} } ]} + +EQMP + + { + .name = "query-nvdimms", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_query_nvdimms, + }, + +SQMP +Show plugged NVDIMM devices +--------------------------- + +Arguments: None. + +Example for pc machine type started with +-object memory-backend-file,id=mem1,mem-path=/path/to/nvm1,size=4G +-device nvdimm,id=nvdimm1,memdev=mem1 +-object memory-backend-file,id=mem2,mem-path=/path/to/nvm2,size=8G +-device nvdimm,id=nvdimm2,memdev=mem2: + +-> { "execute": "query-nvdimms" } +<- { "returns": [ + { + "mem-path": "/path/to/nvm1", + "slot": 0, + "spa": 17179869184, + "length": 4294967296 + }, + { + "mem-path": "/path/to/nvm2", + "slot": 1, + "spa": 21474836480, + "length": 8589934592 + } + ]} diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 4cfb94d..eedc128 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -57,7 +57,7 @@ static int nvdimm_plugged_device_list(Object *obj, void *opaque) * Note: it is the caller's responsibility to free the list to avoid * memory leak. */ -static GSList *nvdimm_get_plugged_device_list(void) +GSList *nvdimm_get_plugged_device_list(void) { GSList *list = NULL; diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index d25993b..99d0cc9 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -26,6 +26,7 @@ #include "qapi/error.h" #include "qapi/visitor.h" #include "hw/mem/nvdimm.h" +#include "qmp-commands.h" static void nvdimm_get_label_size(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -180,3 +181,37 @@ static void nvdimm_register_types(void) } type_init(nvdimm_register_types) + +NvdimmInfoList *qmp_query_nvdimms(Error **errp) +{ + NvdimmInfoList *info_list = NULL; + NvdimmInfoList *info; + GSList *device_list = nvdimm_get_plugged_device_list(); + + while (device_list) { + DeviceState *dev = device_list->data; + PCDIMMDevice *parent = PC_DIMM(OBJECT(dev)); + const char *mem_path; + + info = g_new0(NvdimmInfoList, 1); + info->value = g_new0(NvdimmInfo, 1); + + mem_path = object_property_get_str(OBJECT(parent->hostmem), + "mem-path", NULL); + info->value->mem_path = mem_path ? strdup(mem_path) : NULL; + + info->value->slot = object_property_get_int(OBJECT(dev), + PC_DIMM_SLOT_PROP, NULL); + info->value->spa = object_property_get_int(OBJECT(dev), + PC_DIMM_ADDR_PROP, NULL); + info->value->length = object_property_get_int(OBJECT(dev), + PC_DIMM_SIZE_PROP, NULL); + + info->next = info_list; + info_list = info; + device_list = device_list->next; + } + + g_slist_free(device_list); + return info_list; +} diff --git a/include/hw/mem/nvdimm.h b/include/hw/mem/nvdimm.h index 1cfe9e0..6be269e 100644 --- a/include/hw/mem/nvdimm.h +++ b/include/hw/mem/nvdimm.h @@ -113,4 +113,14 @@ void nvdimm_init_acpi_state(AcpiNVDIMMState *state, MemoryRegion *io, FWCfgState *fw_cfg, Object *owner); void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data, BIOSLinker *linker, GArray *dsm_dma_arrea); + +/* + * Inquire plugged NVDIMM devices and link them into the list which is + * returned to the caller. + * + * Note: it is the caller's responsibility to free the list to avoid + * memory leak. + */ +GSList *nvdimm_get_plugged_device_list(void); + #endif diff --git a/qapi-schema.json b/qapi-schema.json index c3dcf11..6246255 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4646,3 +4646,32 @@ # Since: 2.7 ## { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] } + +## +# @NvdimmInfo +# +# Information about an NVDIMM device. +# +# @mem-path: the backend file of the NVDIMM device +# +# @slot: the slot index of the NVDIMM device +# +# @spa: the 64-bit SPA base address of the NVDIMM device +# +# @length: the 64-bit size in bytes of the NVDIMM device +# +# Since 2.8 +## +{ 'struct': 'NvdimmInfo', + 'data': {'mem-path' : 'str', 'slot': 'int', 'spa': 'int', 'length': 'int'} } + +## +# @query-nvdimms: +# +# Returns information about each NVDIMM device +# +# Returns: a list of @NvdimmInfo for each device +# +# Since: 2.8 +## +{ 'command': 'query-nvdimms', 'returns': ['NvdimmInfo'] }