From patchwork Sun Oct 11 03:52:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 7368141 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B19349F40A for ; Sat, 10 Oct 2015 19:59:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BFF4E20929 for ; Sat, 10 Oct 2015 19:59:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A66252091D for ; Sat, 10 Oct 2015 19:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752748AbbJJT7R (ORCPT ); Sat, 10 Oct 2015 15:59:17 -0400 Received: from mga03.intel.com ([134.134.136.65]:57371 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752732AbbJJT7N (ORCPT ); Sat, 10 Oct 2015 15:59:13 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 10 Oct 2015 12:59:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,664,1437462000"; d="scan'208";a="661783187" Received: from xiaoreal1.sh.intel.com (HELO xiaoreal1.sh.intel.com.sh.intel.com) ([10.239.48.79]) by orsmga003.jf.intel.com with ESMTP; 10 Oct 2015 12:59:10 -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 v3 24/32] nvdimm: init the address region used by DSM method Date: Sun, 11 Oct 2015 11:52:56 +0800 Message-Id: <1444535584-18220-25-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1444535584-18220-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1444535584-18220-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 Signed-off-by: Xiao Guangrong --- hw/mem/nvdimm/acpi.c | 75 ++++++++++++++++++++++++++++++++++++++++++++---- hw/mem/nvdimm/internal.h | 8 ++++++ 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/hw/mem/nvdimm/acpi.c b/hw/mem/nvdimm/acpi.c index 62b1e02..1450a6a 100644 --- a/hw/mem/nvdimm/acpi.c +++ b/hw/mem/nvdimm/acpi.c @@ -271,8 +271,6 @@ static int build_structure_dcr(void *buf, NVDIMMDevice *nvdimm) static void build_device_structure(GSList *device_list, char *buf) { - buf += sizeof(nfit); - for (; device_list; device_list = device_list->next) { NVDIMMDevice *nvdimm = device_list->data; @@ -290,7 +288,7 @@ static void build_device_structure(GSList *device_list, char *buf) } } -static void build_nfit(GSList *device_list, GArray *table_offsets, +static void build_nfit(void *fit, GSList *device_list, GArray *table_offsets, GArray *table_data, GArray *linker) { size_t total; @@ -304,12 +302,76 @@ static void build_nfit(GSList *device_list, GArray *table_offsets, acpi_add_table(table_offsets, table_data); buf = acpi_data_push(table_data, total); - build_device_structure(device_list, buf); + memcpy(buf + sizeof(nfit), fit, total - sizeof(nfit)); build_header(linker, table_data, (void *)(table_data->data + nfit_start), "NFIT", table_data->len - nfit_start, 1); } +static uint64_t dsm_read(void *opaque, hwaddr addr, + unsigned size) +{ + return 0; +} + +static void dsm_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ +} + +static const MemoryRegionOps dsm_ops = { + .read = dsm_read, + .write = dsm_write, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static MemoryRegion *build_dsm_memory(NVDIMMState *state) +{ + MemoryRegion *dsm_ram_mr, *dsm_mmio_mr, *dsm_fit_mr; + uint64_t fit_size = memory_region_size(&state->mr) - state->page_size * 2; + + /* DSM memory has already been built. */ + dsm_fit_mr = memory_region_find(&state->mr, state->page_size * 2, + fit_size).mr; + if (dsm_fit_mr) { + nvdebug("DSM FIT has already been built by %s.\n", dsm_fit_mr->name); + memory_region_unref(dsm_fit_mr); + 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, &dsm_ops, state, + "nvdimm.dsm_mmio", state->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", + state->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, state->page_size, dsm_ram_mr); + memory_region_add_subregion(&state->mr, state->page_size * 2, dsm_fit_mr); + + return dsm_fit_mr; +} + void nvdimm_build_acpi_table(NVDIMMState *state, GArray *table_offsets, GArray *table_data, GArray *linker) { @@ -321,7 +383,10 @@ void nvdimm_build_acpi_table(NVDIMMState *state, GArray *table_offsets, } if (device_list) { - build_nfit(device_list, table_offsets, table_data, linker); + void *fit = memory_region_get_ram_ptr(build_dsm_memory(state)); + + build_device_structure(device_list, fit); + build_nfit(fit, device_list, table_offsets, table_data, linker); g_slist_free(device_list); } } diff --git a/hw/mem/nvdimm/internal.h b/hw/mem/nvdimm/internal.h index 5551448..1e95363 100644 --- a/hw/mem/nvdimm/internal.h +++ b/hw/mem/nvdimm/internal.h @@ -13,6 +13,14 @@ #ifndef NVDIMM_INTERNAL_H #define NVDIMM_INTERNAL_H +#define NVDIMM_DEBUG 0 +#define nvdebug(fmt, ...) \ + do { \ + if (NVDIMM_DEBUG) { \ + fprintf(stderr, "nvdimm: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) + #define MIN_NAMESPACE_LABEL_SIZE (128UL << 10) struct uuid_le {