From patchwork Fri Aug 14 14:51:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 507438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0EF0C1401E7 for ; Sat, 15 Aug 2015 01:04:49 +1000 (AEST) Received: from localhost ([::1]:46707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQGXH-0007fZ-5r for incoming@patchwork.ozlabs.org; Fri, 14 Aug 2015 11:04:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQGR7-0004Q7-Ka for qemu-devel@nongnu.org; Fri, 14 Aug 2015 10:58:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZQGR5-0005V6-TZ for qemu-devel@nongnu.org; Fri, 14 Aug 2015 10:58:25 -0400 Received: from mga02.intel.com ([134.134.136.20]:37893) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQGR5-0005QN-4H for qemu-devel@nongnu.org; Fri, 14 Aug 2015 10:58:23 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 14 Aug 2015 07:58:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,678,1432623600"; d="scan'208";a="748633298" Received: from xiao.sh.intel.com ([10.239.159.86]) by orsmga001.jf.intel.com with ESMTP; 14 Aug 2015 07:58:17 -0700 From: Xiao Guangrong To: pbonzini@redhat.com, imammedo@redhat.com Date: Fri, 14 Aug 2015 22:51:59 +0800 Message-Id: <1439563931-12352-7-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1439563931-12352-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1439563931-12352-1-git-send-email-guangrong.xiao@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Cc: Xiao Guangrong , ehabkost@redhat.com, kvm@vger.kernel.org, mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, rth@twiddle.net Subject: [Qemu-devel] [PATCH v2 06/18] pc: implement NVDIMM device abstract X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Introduce "pc-nvdimm" device and it has two parameters: - @file, which is the backed memory file for NVDIMM device - @configdata, specify if we need to reserve 128k at the end of @file for nvdimm device's config data. Default is false If @configdata is false, Qemu will build a static and readonly namespace in memory and use it serveing for DSM GET_CONFIG_SIZE/GET_CONFIG_DATA requests. This is good for the user who want to pass whole nvdimm device and make its data is complete visible to guest We can use "-device pc-nvdimm,file=/dev/pmem,configdata" in the Qemu command to create NVDIMM device for the guest Signed-off-by: Xiao Guangrong --- default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/Makefile.objs | 2 +- hw/mem/Makefile.objs | 1 + hw/mem/nvdimm/pc-nvdimm.c | 99 ++++++++++++++++++++++++++++++++++++++ include/hw/mem/pc-nvdimm.h | 31 ++++++++++++ 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 hw/mem/nvdimm/pc-nvdimm.c create mode 100644 include/hw/mem/pc-nvdimm.h diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 48b5762..67fc3a8 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -49,3 +49,4 @@ CONFIG_MEM_HOTPLUG=y CONFIG_XIO3130=y CONFIG_IOH3420=y CONFIG_I82801B11=y +CONFIG_NVDIMM=y diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak index 4962ed7..dfcde36 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -50,3 +50,4 @@ CONFIG_MEM_HOTPLUG=y CONFIG_XIO3130=y CONFIG_IOH3420=y CONFIG_I82801B11=y +CONFIG_NVDIMM=y diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 73afa41..1e25d3f 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -30,7 +30,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += vfio/ devices-dirs-$(CONFIG_VIRTIO) += virtio/ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ devices-dirs-$(CONFIG_SOFTMMU) += xen/ -devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/ +devices-dirs-y += mem/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs index b000fb4..4df7482 100644 --- a/hw/mem/Makefile.objs +++ b/hw/mem/Makefile.objs @@ -1 +1,2 @@ common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o +common-obj-$(CONFIG_NVDIMM) += nvdimm/pc-nvdimm.o diff --git a/hw/mem/nvdimm/pc-nvdimm.c b/hw/mem/nvdimm/pc-nvdimm.c new file mode 100644 index 0000000..a53d235 --- /dev/null +++ b/hw/mem/nvdimm/pc-nvdimm.c @@ -0,0 +1,99 @@ +/* + * NVDIMM (A Non-Volatile Dual In-line Memory Module) Virtualization Implement + * + * Copyright(C) 2015 Intel Corporation. + * + * Author: + * Xiao Guangrong + * + * Currently, it only supports PMEM Virtualization. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "hw/mem/pc-nvdimm.h" + +static char *get_file(Object *obj, Error **errp) +{ + PCNVDIMMDevice *nvdimm = PC_NVDIMM(obj); + + return g_strdup(nvdimm->file); +} + +static void set_file(Object *obj, const char *str, Error **errp) +{ + PCNVDIMMDevice *nvdimm = PC_NVDIMM(obj); + + if (nvdimm->file) { + g_free(nvdimm->file); + } + + nvdimm->file = g_strdup(str); +} + +static bool has_configdata(Object *obj, Error **errp) +{ + PCNVDIMMDevice *nvdimm = PC_NVDIMM(obj); + + return nvdimm->configdata; +} + +static void set_configdata(Object *obj, bool value, Error **errp) +{ + PCNVDIMMDevice *nvdimm = PC_NVDIMM(obj); + + nvdimm->configdata = value; +} + +static void pc_nvdimm_init(Object *obj) +{ + object_property_add_str(obj, "file", get_file, set_file, NULL); + object_property_add_bool(obj, "configdata", has_configdata, + set_configdata, NULL); +} + +static void pc_nvdimm_realize(DeviceState *dev, Error **errp) +{ + PCNVDIMMDevice *nvdimm = PC_NVDIMM(dev); + + if (!nvdimm->file) { + error_setg(errp, "file property is not set"); + } +} + +static void pc_nvdimm_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + /* nvdimm hotplug has not been supported yet. */ + dc->hotpluggable = false; + + dc->realize = pc_nvdimm_realize; + dc->desc = "NVDIMM memory module"; +} + +static TypeInfo pc_nvdimm_info = { + .name = TYPE_PC_NVDIMM, + .parent = TYPE_DEVICE, + .instance_size = sizeof(PCNVDIMMDevice), + .instance_init = pc_nvdimm_init, + .class_init = pc_nvdimm_class_init, +}; + +static void pc_nvdimm_register_types(void) +{ + type_register_static(&pc_nvdimm_info); +} + +type_init(pc_nvdimm_register_types) diff --git a/include/hw/mem/pc-nvdimm.h b/include/hw/mem/pc-nvdimm.h new file mode 100644 index 0000000..51152b8 --- /dev/null +++ b/include/hw/mem/pc-nvdimm.h @@ -0,0 +1,31 @@ +/* + * NVDIMM (A Non-Volatile Dual In-line Memory Module) Virtualization Implement + * + * Copyright(C) 2015 Intel Corporation. + * + * Author: + * Xiao Guangrong + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef __PC_NVDIMM_H +#define __PC_NVDIMM_H + +#include "hw/qdev.h" + +typedef struct PCNVDIMMDevice { + /* private */ + DeviceState parent_obj; + + char *file; + bool configdata; +} PCNVDIMMDevice; + +#define TYPE_PC_NVDIMM "pc-nvdimm" + +#define PC_NVDIMM(obj) \ + OBJECT_CHECK(PCNVDIMMDevice, (obj), TYPE_PC_NVDIMM) + +#endif