From patchwork Mon Oct 19 00:54:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 7431241 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 083DABEEA4 for ; Sun, 18 Oct 2015 17:00:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 086FB20621 for ; Sun, 18 Oct 2015 17:00:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EC4E92061E for ; Sun, 18 Oct 2015 17:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932300AbbJRRAf (ORCPT ); Sun, 18 Oct 2015 13:00:35 -0400 Received: from mga11.intel.com ([192.55.52.93]:15782 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932298AbbJRRA2 (ORCPT ); Sun, 18 Oct 2015 13:00:28 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 18 Oct 2015 10:00:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,698,1437462000"; d="scan'208";a="583275937" Received: from xiaoreal1.sh.intel.com (HELO xiaoreal1.sh.intel.com.sh.intel.com) ([10.239.48.79]) by FMSMGA003.fm.intel.com with ESMTP; 18 Oct 2015 10:00:26 -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, dan.j.williams@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, Xiao Guangrong Subject: [PATCH v4 25/33] nvdimm acpi: init the address region used by DSM Date: Mon, 19 Oct 2015 08:54:11 +0800 Message-Id: <1445216059-88521-26-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1445216059-88521-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1445216059-88521-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=-5.0 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_HI, T_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 Map the NVDIMM ACPI memory region to guest address space Detailed DSM design please refer to docs/specs/acpi_nvdimm.txt Signed-off-by: Xiao Guangrong --- hw/acpi/nvdimm.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--- include/hw/mem/nvdimm.h | 8 +++++ 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 8d8376c..bc28828 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -391,10 +391,9 @@ static GArray *nvdimm_build_device_structure(GSList *device_list) return structures; } -static void nvdimm_build_nfit(GSList *device_list, GArray *table_offsets, +static void nvdimm_build_nfit(GArray *structures, GArray *table_offsets, GArray *table_data, GArray *linker) { - GArray *structures = nvdimm_build_device_structure(device_list); void *header; acpi_add_table(table_offsets, table_data); @@ -407,12 +406,80 @@ static void nvdimm_build_nfit(GSList *device_list, GArray *table_offsets, build_header(linker, table_data, header, "NFIT", sizeof(nfit) + structures->len, 1); - g_array_free(structures, true); +} + +static uint64_t +nvdimm_dsm_read(void *opaque, hwaddr addr, unsigned size) +{ + return 0; +} + +static void +nvdimm_dsm_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) +{ +} + +static const MemoryRegionOps nvdimm_dsm_ops = { + .read = nvdimm_dsm_read, + .write = nvdimm_dsm_write, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static MemoryRegion *nvdimm_build_dsm_memory(NVDIMMState *state) +{ + MemoryRegion *dsm_ram_mr, *dsm_mmio_mr, *dsm_fit_mr; + uint64_t page_size = getpagesize(); + uint64_t fit_size = memory_region_size(&state->mr) - page_size * 2; + + /* DSM memory has already been built. */ + dsm_fit_mr = memory_region_find(&state->mr, page_size * 2, + fit_size).mr; + if (dsm_fit_mr) { + nvdimm_debug("DSM FIT has already been built by %s.\n", + dsm_fit_mr->name); + return dsm_fit_mr; + } + + /* + * the first page is MMIO-based used to transfer control from guest + * ACPI to QEMU. + */ + dsm_mmio_mr = g_new(MemoryRegion, 1); + memory_region_init_io(dsm_mmio_mr, NULL, &nvdimm_dsm_ops, state, + "nvdimm.dsm_mmio", page_size); + + /* + * the second page is RAM-based used to transfer data between guest + * ACPI and QEMU. + */ + dsm_ram_mr = g_new(MemoryRegion, 1); + memory_region_init_ram(dsm_ram_mr, NULL, "nvdimm.dsm_ram", + page_size, &error_abort); + vmstate_register_ram_global(dsm_ram_mr); + + /* + * the left is RAM-based which is _FIT buffer returned by _FIT + * method. + */ + dsm_fit_mr = g_new(MemoryRegion, 1); + memory_region_init_ram(dsm_fit_mr, NULL, "nvdimm.fit", fit_size, + &error_abort); + vmstate_register_ram_global(dsm_fit_mr); + + memory_region_add_subregion(&state->mr, 0, dsm_mmio_mr); + memory_region_add_subregion(&state->mr, page_size, dsm_ram_mr); + memory_region_add_subregion(&state->mr, page_size * 2, dsm_fit_mr); + + /* the caller will unref it. */ + memory_region_ref(dsm_fit_mr); + return dsm_fit_mr; } void nvdimm_build_acpi(NVDIMMState *state, GArray *table_offsets, GArray *table_data, GArray *linker) { + MemoryRegion *fit_mr; + GArray *structures; GSList *device_list = nvdimm_get_plugged_device_list(); if (!memory_region_size(&state->mr)) { @@ -424,6 +491,18 @@ void nvdimm_build_acpi(NVDIMMState *state, GArray *table_offsets, return; } - nvdimm_build_nfit(device_list, table_offsets, table_data, linker); + fit_mr = nvdimm_build_dsm_memory(state); + + structures = nvdimm_build_device_structure(device_list); + + /* Build fit memory which is presented to guest via _FIT method. */ + assert(memory_region_size(fit_mr) >= structures->len); + memcpy(memory_region_get_ram_ptr(fit_mr), structures->data, + structures->len); + + nvdimm_build_nfit(structures, table_offsets, table_data, linker); + + memory_region_unref(fit_mr); g_slist_free(device_list); + g_array_free(structures, true); } diff --git a/include/hw/mem/nvdimm.h b/include/hw/mem/nvdimm.h index dc77a1f..c2dc635 100644 --- a/include/hw/mem/nvdimm.h +++ b/include/hw/mem/nvdimm.h @@ -25,6 +25,14 @@ #include "hw/mem/dimm.h" +#define NVDIMM_DEBUG 0 +#define nvdimm_debug(fmt, ...) \ + do { \ + if (NVDIMM_DEBUG) { \ + fprintf(stderr, "nvdimm: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) + /* * The minimum label data size is required by NVDIMM Namespace * specification, please refer to chapter 2 Namespaces: