From patchwork Mon Oct 10 00:34:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9368839 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 14CDC6048F for ; Mon, 10 Oct 2016 00:39:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AEA428B40 for ; Mon, 10 Oct 2016 00:39:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F35E128B4D; Mon, 10 Oct 2016 00:39:51 +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 B904F28B40 for ; Mon, 10 Oct 2016 00:39:50 +0000 (UTC) Received: from localhost ([::1]:46613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOdB-0001CQ-RD for patchwork-qemu-devel@patchwork.kernel.org; Sun, 09 Oct 2016 20:39:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOYi-00068I-DC for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btOYe-0003HQ-56 for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:11 -0400 Received: from mga02.intel.com ([134.134.136.20]:27981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btOYd-0003GZ-Pf for qemu-devel@nongnu.org; Sun, 09 Oct 2016 20:35:08 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP; 09 Oct 2016 17:35:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,469,1473145200"; d="scan'208";a="178161436" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.148]) by fmsmga004.fm.intel.com with ESMTP; 09 Oct 2016 17:35:05 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xensource.com Date: Mon, 10 Oct 2016 08:34:20 +0800 Message-Id: <20161010003423.4333-6-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.20 Subject: [Qemu-devel] [RFC QEMU PATCH 5/8] nvdimm acpi: build and copy NVDIMM namespace devices to guest on Xen 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 , Igor Mammedov , "Michael S. Tsirkin" , Xiao Guangrong , Konrad Rzeszutek Wilk Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Build and copy NVDIMM namespace devices to guest when QEMU is used as the device model of Xen. Only the body of each AML device is built and copied, Xen hvmloader will build the complete namespace devices from them and put in SSDT tables. Signed-off-by: Haozhong Zhang --- Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Xiao Guangrong --- hw/acpi/aml-build.c | 2 +- hw/acpi/nvdimm.c | 58 +++++++++++++++++++++++++++------------------ include/hw/acpi/aml-build.h | 2 ++ 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index a749b62..eda999f 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -287,7 +287,7 @@ build_append_named_dword(GArray *array, const char *name_format, ...) static GPtrArray *alloc_list; -static Aml *aml_alloc(void) +Aml *aml_alloc(void) { Aml *var = g_new0(typeof(*var), 1); diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 6de2301..4cfb94d 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -925,17 +925,22 @@ static void nvdimm_build_ssdt(GSList *device_list, GArray *table_offsets, GArray *table_data, BIOSLinker *linker, GArray *dsm_dma_arrea) { - Aml *ssdt, *sb_scope, *dev, *field; + Aml *ssdt, *sb_scope = NULL, *dev, *field; int mem_addr_offset, nvdimm_ssdt; acpi_add_table(table_offsets, table_data); ssdt = init_aml_allocator(); - acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader)); - sb_scope = aml_scope("\\_SB"); + if (xen_enabled()) { + dev = aml_alloc(); + } else { + acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader)); + + sb_scope = aml_scope("\\_SB"); - dev = aml_device("NVDR"); + dev = aml_device("NVDR"); + } /* * ACPI 6.0: 9.20 NVDIMM Devices: @@ -1014,25 +1019,32 @@ static void nvdimm_build_ssdt(GSList *device_list, GArray *table_offsets, nvdimm_build_nvdimm_devices(device_list, dev); - aml_append(sb_scope, dev); - aml_append(ssdt, sb_scope); - - nvdimm_ssdt = table_data->len; - - /* copy AML table into ACPI tables blob and patch header there */ - g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len); - mem_addr_offset = build_append_named_dword(table_data, - NVDIMM_ACPI_MEM_ADDR); - - bios_linker_loader_alloc(linker, - NVDIMM_DSM_MEM_FILE, dsm_dma_arrea, - sizeof(NvdimmDsmIn), false /* high memory */); - bios_linker_loader_add_pointer(linker, - ACPI_BUILD_TABLE_FILE, mem_addr_offset, sizeof(uint32_t), - NVDIMM_DSM_MEM_FILE, 0); - build_header(linker, table_data, - (void *)(table_data->data + nvdimm_ssdt), - "SSDT", table_data->len - nvdimm_ssdt, 1, NULL, "NVDIMM"); + if (xen_enabled()) { + build_append_named_dword(dev->buf, NVDIMM_ACPI_MEM_ADDR); + xen_acpi_copy_to_guest("NVDR", dev->buf->data, dev->buf->len, + XEN_ACPI_NSDEV); + } else { + aml_append(sb_scope, dev); + aml_append(ssdt, sb_scope); + + nvdimm_ssdt = table_data->len; + + /* copy AML table into ACPI tables blob and patch header there */ + g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len); + mem_addr_offset = build_append_named_dword(table_data, + NVDIMM_ACPI_MEM_ADDR); + + bios_linker_loader_alloc(linker, + NVDIMM_DSM_MEM_FILE, dsm_dma_arrea, + sizeof(NvdimmDsmIn), false /* high memory */); + bios_linker_loader_add_pointer(linker, + ACPI_BUILD_TABLE_FILE, mem_addr_offset, + sizeof(uint32_t), + NVDIMM_DSM_MEM_FILE, 0); + build_header(linker, table_data, + (void *)(table_data->data + nvdimm_ssdt), + "SSDT", table_data->len - nvdimm_ssdt, 1, NULL, "NVDIMM"); + } free_aml_allocator(); } diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 559326c..bf02f91 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -232,6 +232,8 @@ Aml *init_aml_allocator(void); */ void free_aml_allocator(void); +Aml *aml_alloc(void); + /** * aml_append: * @parent_ctx: context to which @child element is added