diff mbox

[Xen-devel,RESEND,14/14] libxc/xc_dom_core: Copy ACPI tables to guest memory space

Message ID 1464670986-10256-15-git-send-email-zhaoshenglong@huawei.com
State New
Headers show

Commit Message

Shannon Zhao May 31, 2016, 5:03 a.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>

Copy all the ACPI tables to guest memory space and also initialize the
address of the tables.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 tools/libxc/xc_dom_core.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
diff mbox

Patch

diff --git a/tools/libxc/xc_dom_core.c b/tools/libxc/xc_dom_core.c
index 55c779d..6d91a46 100644
--- a/tools/libxc/xc_dom_core.c
+++ b/tools/libxc/xc_dom_core.c
@@ -33,6 +33,7 @@ 
 
 #include "xg_private.h"
 #include "xc_dom.h"
+#include "acpi_defs.h"
 
 /* ------------------------------------------------------------------------ */
 /* debugging                                                                */
@@ -1096,6 +1097,64 @@  int xc_dom_build_image(struct xc_dom_image *dom)
         memcpy(devicetreemap, dom->devicetree_blob, dom->devicetree_size);
     }
 
+    /* load ACPI tables */
+    if ( dom->acpitable_blob )
+    {
+        void *acpitablemap;
+        uint64_t start = dom->acpi_seg.vstart;
+        struct acpi_xsdt_descriptor *xsdt;
+        struct acpi_rsdp_descriptor *rsdp;
+        struct acpi_fadt_descriptor *fadt;
+
+        if ( xc_dom_alloc_segment(dom, &dom->acpi_seg, "acpitable",
+                                  start, dom->acpitable_size) != 0 )
+            goto err;
+
+        acpitablemap = xc_dom_seg_to_ptr(dom, &dom->acpi_seg);
+        if ( acpitablemap == NULL )
+        {
+            DOMPRINTF("%s: xc_dom_seg_to_ptr(dom, &dom->acpi_seg) => NULL",
+                      __FUNCTION__);
+            goto err;
+        }
+
+        rsdp = (struct acpi_rsdp_descriptor *)acpitablemap;
+        memcpy(acpitablemap, dom->acpitable_blob->rsdp.table,
+               dom->acpitable_blob->rsdp.size);
+        start += dom->acpitable_blob->rsdp.size;
+        acpitablemap += dom->acpitable_blob->rsdp.size;
+
+        xsdt = (struct acpi_xsdt_descriptor *)acpitablemap;
+        memcpy(acpitablemap, dom->acpitable_blob->xsdt.table,
+               dom->acpitable_blob->xsdt.size);
+        rsdp->xsdt_physical_address = start;
+        start += dom->acpitable_blob->xsdt.size;
+        acpitablemap += dom->acpitable_blob->xsdt.size;
+
+        memcpy(acpitablemap, dom->acpitable_blob->madt.table,
+               dom->acpitable_blob->madt.size);
+        xsdt->entry[0] = start;
+        start += dom->acpitable_blob->madt.size;
+        acpitablemap += dom->acpitable_blob->madt.size;
+
+        memcpy(acpitablemap, dom->acpitable_blob->gtdt.table,
+               dom->acpitable_blob->gtdt.size);
+        xsdt->entry[1] = start;
+        start += dom->acpitable_blob->gtdt.size;
+        acpitablemap += dom->acpitable_blob->gtdt.size;
+
+        fadt = (struct acpi_fadt_descriptor *)acpitablemap;
+        memcpy(acpitablemap, dom->acpitable_blob->fadt.table,
+               dom->acpitable_blob->fadt.size);
+        xsdt->entry[2] = start;
+        start += dom->acpitable_blob->fadt.size;
+        acpitablemap += dom->acpitable_blob->fadt.size;
+
+        memcpy(acpitablemap, dom->acpitable_blob->dsdt.table,
+               dom->acpitable_blob->dsdt.size);
+        fadt->dsdt = start;
+    }
+
     /* allocate other pages */
     if ( !dom->arch_hooks->p2m_base_supported ||
          dom->parms.p2m_base >= dom->parms.virt_base ||