From patchwork Wed Jul 1 14:50:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 6703971 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4A9FCC05AC for ; Wed, 1 Jul 2015 14:55:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 72B202064C for ; Wed, 1 Jul 2015 14:55:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48ED020708 for ; Wed, 1 Jul 2015 14:55:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754371AbbGAOzi (ORCPT ); Wed, 1 Jul 2015 10:55:38 -0400 Received: from mga03.intel.com ([134.134.136.65]:20064 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754328AbbGAOzd (ORCPT ); Wed, 1 Jul 2015 10:55:33 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 01 Jul 2015 07:55:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,386,1432623600"; d="scan'208";a="517239293" Received: from xiao.sh.intel.com ([10.239.159.86]) by FMSMGA003.fm.intel.com with ESMTP; 01 Jul 2015 07:55:31 -0700 From: Xiao Guangrong To: pbonzini@redhat.com, imammedo@redhat.com Cc: gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, mst@redhat.com, rth@twiddle.net, ehabkost@redhat.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, Xiao Guangrong Subject: [PATCH 06/16] pc: implement NVDIMM device abstract Date: Wed, 1 Jul 2015 22:50:22 +0800 Message-Id: <1435762232-15543-7-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1435762232-15543-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1435762232-15543-1-git-send-email-guangrong.xiao@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce "pc-nvdimm" device and it only has one parameter, @file, which is the backed memory file for NVDIMM device We can use "-device pc-nvdimm,file=/dev/pmem" in the Qemu command to create NVDIMM device for the guest Signed-off-by: Xiao Guangrong --- hw/mem/Makefile.objs | 1 + hw/mem/pc-nvdimm.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++ include/hw/mem/pc-nvdimm.h | 32 ++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 hw/mem/pc-nvdimm.c create mode 100644 include/hw/mem/pc-nvdimm.h diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs index b000fb4..9a7f5a9 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_LINUX) += pc-nvdimm.o diff --git a/hw/mem/pc-nvdimm.c b/hw/mem/pc-nvdimm.c new file mode 100644 index 0000000..0209ea9 --- /dev/null +++ b/hw/mem/pc-nvdimm.c @@ -0,0 +1,83 @@ +/* + * 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 void pc_nvdimm_init(Object *obj) +{ + object_property_add_str(obj, "file", get_file, set_file, 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 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..7f37b46 --- /dev/null +++ b/include/hw/mem/pc-nvdimm.h @@ -0,0 +1,32 @@ +/* + * 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" + +#ifdef CONFIG_LINUX +typedef struct PCNVDIMMDevice { + /* private */ + DeviceState parent_obj; + + char *file; +} PCNVDIMMDevice; + +#define TYPE_PC_NVDIMM "pc-nvdimm" + +#define PC_NVDIMM(obj) \ + OBJECT_CHECK(PCNVDIMMDevice, (obj), TYPE_PC_NVDIMM) +#else /* !CONFIG_LINUX */ +#endif +#endif