diff mbox

[RFC,QEMU,5/8] nvdimm acpi: build and copy NVDIMM namespace devices to guest on Xen

Message ID 20161010003423.4333-6-haozhong.zhang@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Haozhong Zhang Oct. 10, 2016, 12:34 a.m. UTC
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 mbox

Patch

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