From: Haozhong Zhang <haozhong.zhang@intel.com>
To: qemu-devel@nongnu.org, xen-devel@lists.xensource.com
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
	Igor Mammedov <imammedo@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Xiao Guangrong <guangrong.xiao@linux.intel.com>
Subject: [RFC QEMU PATCH 5/8] nvdimm acpi: build and copy NVDIMM namespace devices to guest on Xen
Date: Mon, 10 Oct 2016 08:34:20 +0800	[thread overview]
Message-ID: <20161010003423.4333-6-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20161010003423.4333-1-haozhong.zhang@intel.com>
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 <haozhong.zhang@intel.com>
---
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
 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
-- 
2.10.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply	other threads:[~2016-10-10  0:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10  0:34 [RFC QEMU PATCH 0/8] Implement vNVDIMM for Xen HVM guest Haozhong Zhang
2016-10-10  0:34 ` [RFC QEMU PATCH 1/8] nvdimm: do not initialize label_data if label_size is zero Haozhong Zhang
2017-02-15 22:18   ` Konrad Rzeszutek Wilk
2016-10-10  0:34 ` [RFC QEMU PATCH 2/8] xen-hvm: add a function to copy ACPI to guest Haozhong Zhang
2016-10-10  0:34 ` [RFC QEMU PATCH 3/8] nvdimm acpi: do not use fw_cfg on Xen Haozhong Zhang
2016-10-10  0:34 ` [RFC QEMU PATCH 4/8] nvdimm acpi: build and copy NFIT to guest " Haozhong Zhang
2016-10-10  0:34 ` Haozhong Zhang [this message]
2016-10-10  0:34 ` [RFC QEMU PATCH 6/8] hostmem: add a host memory backend for Xen Haozhong Zhang
2016-10-10  0:34 ` [RFC QEMU PATCH 7/8] xen-hvm: create hotplug memory region for HVM guest Haozhong Zhang
2016-10-10  0:34 ` [RFC QEMU PATCH 8/8] qmp: add a qmp command 'query-nvdimms' to get plugged NVDIMM devices Haozhong Zhang
2016-10-10 19:16   ` Eric Blake
2016-10-11  6:31     ` Haozhong Zhang
2016-10-11  8:22       ` Markus Armbruster
2016-10-11 10:12         ` Haozhong Zhang
2016-10-11 14:45         ` Eric Blake
2016-10-10 16:52 ` [RFC QEMU PATCH 0/8] Implement vNVDIMM for Xen HVM guest no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=20161010003423.4333-6-haozhong.zhang@intel.com \
    --to=haozhong.zhang@intel.com \
    --cc=guangrong.xiao@linux.intel.com \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).