xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Shannon Zhao <zhaoshenglong@huawei.com>
To: xen-devel@lists.xen.org
Cc: hangaohuai@huawei.com, sstabellini@kernel.org,
	wei.liu2@citrix.com, ian.jackson@eu.citrix.com,
	peter.huangpeng@huawei.com, julien.grall@arm.com,
	shannon.zhao@linaro.org, boris.ostrovsky@oracle.com
Subject: [PATCH v3 06/17] libxl/arm: Estimate the size of ACPI tables
Date: Tue, 5 Jul 2016 11:12:36 +0800	[thread overview]
Message-ID: <1467688367-17320-7-git-send-email-zhaoshenglong@huawei.com> (raw)
In-Reply-To: <1467688367-17320-1-git-send-email-zhaoshenglong@huawei.com>

From: Shannon Zhao <shannon.zhao@linaro.org>

Estimate the size of ACPI tables and reserve a memory map space for ACPI
tables.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c  | 85 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/arch-arm.h |  4 ++
 2 files changed, 89 insertions(+)

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index d1c066d..7a59126 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -33,11 +33,92 @@ extern const unsigned char dsdt_anycpu_arm[];
 _hidden
 extern const int dsdt_anycpu_arm_len;
 
+enum {
+    RSDP,
+    XSDT,
+    GTDT,
+    MADT,
+    FADT,
+    DSDT,
+    NUMS,
+};
+
+struct acpitable {
+    uint64_t addr;
+    size_t size;
+};
+
+static int libxl__estimate_acpi_size(libxl__gc *gc,
+                                     libxl_domain_build_info *info,
+                                     struct xc_dom_image *dom,
+                                     xc_domain_configuration_t *xc_config,
+                                     struct acpitable acpitables[])
+{
+    uint64_t size;
+
+    acpitables[RSDP].addr = GUEST_ACPI_BASE;
+    acpitables[RSDP].size = sizeof(struct acpi_table_rsdp);
+    dom->acpitable_size += ROUNDUP(acpitables[RSDP].size, 3);
+
+    acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpitable_size;
+    /*
+     * Currently only 3 tables(GTDT, FADT, MADT) are pointed by XSDT. Alloc
+     * entries for them.
+     */
+    acpitables[XSDT].size = sizeof(struct acpi_table_xsdt) +
+                            sizeof(uint64_t) * 2;
+    dom->acpitable_size += ROUNDUP(acpitables[XSDT].size, 3);
+
+    acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpitable_size;
+    acpitables[GTDT].size = sizeof(struct acpi_table_gtdt);
+    dom->acpitable_size += ROUNDUP(acpitables[GTDT].size, 3);
+
+    acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpitable_size;
+
+    switch (xc_config->gic_version) {
+    case XEN_DOMCTL_CONFIG_GIC_V2:
+        size = sizeof(struct acpi_table_madt) +
+               sizeof(struct acpi_madt_generic_interrupt) * info->max_vcpus +
+               sizeof(struct acpi_madt_generic_distributor);
+        break;
+    case XEN_DOMCTL_CONFIG_GIC_V3:
+        size = sizeof(struct acpi_table_madt) +
+               sizeof(struct acpi_madt_generic_interrupt) * info->max_vcpus +
+               sizeof(struct acpi_madt_generic_distributor) +
+               sizeof(struct acpi_madt_generic_redistributor);
+        break;
+    default:
+        LOG(ERROR, "Unknown GIC version");
+        return ERROR_FAIL;
+    }
+
+    acpitables[MADT].size = size;
+    dom->acpitable_size += ROUNDUP(acpitables[MADT].size, 3);
+
+    acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpitable_size;
+    acpitables[FADT].size = sizeof(struct acpi_table_fadt);
+    dom->acpitable_size += ROUNDUP(acpitables[FADT].size, 3);
+
+    acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpitable_size;
+    acpitables[DSDT].size = dsdt_anycpu_arm_len;
+    dom->acpitable_size += ROUNDUP(acpitables[DSDT].size, 3);
+
+    assert(dom->acpitable_size <= GUEST_ACPI_SIZE);
+    dom->acpitable_blob = libxl__zalloc(gc, dom->acpitable_size);
+
+    return 0;
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
                         libxl__domain_build_state *state,
                         struct xc_dom_image *dom)
 {
     const libxl_version_info *vers;
+    int rc;
+    struct acpitable acpitables[NUMS];
+
+    /* convenience aliases */
+    xc_domain_configuration_t *xc_config = &state->config;
 
     vers = libxl_get_version_info(CTX);
     if (vers == NULL)
@@ -49,6 +130,10 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
     dom->acpitable_blob = NULL;
     dom->acpitable_size = 0;
 
+    rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables);
+    if (rc)
+        return rc;
+
     return 0;
 }
 
diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h
index 4a49254..008a2a0 100644
--- a/xen/include/public/arch-arm.h
+++ b/xen/include/public/arch-arm.h
@@ -406,6 +406,10 @@ typedef uint64_t xen_callback_t;
 #define GUEST_GICV3_GICR0_BASE     0x03020000ULL    /* vCPU0 - vCPU127 */
 #define GUEST_GICV3_GICR0_SIZE     0x01000000ULL
 
+/* ACPI tables physical address */
+#define GUEST_ACPI_BASE 0x20000000ULL
+#define GUEST_ACPI_SIZE 0x00200000ULL
+
 /*
  * 16MB == 4096 pages reserved for guest to use as a region to map its
  * grant table in.
-- 
2.0.4



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-07-05  3:12 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-05  3:12 [PATCH v3 00/17] Xen ARM DomU ACPI support Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 01/17] libxl/arm: Factor out codes for generating DTB Shannon Zhao
2016-07-07 15:41   ` Wei Liu
2016-07-07 15:48     ` Boris Ostrovsky
2016-07-07 16:06       ` Julien Grall
2016-07-07 16:09         ` Wei Liu
2016-07-07 16:12         ` Boris Ostrovsky
2016-07-07 16:15           ` Julien Grall
2016-07-07 16:16           ` Wei Liu
2016-07-07 16:08       ` Wei Liu
2016-07-05  3:12 ` [PATCH v3 02/17] libxc: Add placeholders for ACPI tables blob and size Shannon Zhao
2016-07-07 15:42   ` Wei Liu
2016-07-05  3:12 ` [PATCH v3 03/17] libxl/arm: Add a configuration option for ARM DomU ACPI Shannon Zhao
2016-07-07 15:48   ` Wei Liu
2016-07-05  3:12 ` [PATCH v3 04/17] libxl/arm: prepare for constructing ACPI tables Shannon Zhao
2016-07-07 15:50   ` Wei Liu
2016-07-12  7:05     ` Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 05/17] libxl/arm: Generate static ACPI DSDT table Shannon Zhao
2016-07-07 15:52   ` Wei Liu
2016-07-12  3:50     ` Shannon Zhao
2016-07-12 11:38       ` Wei Liu
2016-07-12 14:49         ` Shannon Zhao
2016-07-05  3:12 ` Shannon Zhao [this message]
2016-07-07 16:07   ` [PATCH v3 06/17] libxl/arm: Estimate the size of ACPI tables Wei Liu
2016-07-07 16:39     ` Julien Grall
2016-07-08 10:45       ` Wei Liu
2016-07-05  3:12 ` [PATCH v3 07/17] libxl/arm: Construct ACPI RSDP table Shannon Zhao
2016-07-07 22:43   ` Boris Ostrovsky
2016-07-08  3:31     ` Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 08/17] libxl/arm: Construct ACPI XSDT table Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 09/17] libxl/arm: Construct ACPI GTDT table Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 10/17] libxl/arm: Factor MPIDR computing codes out as a helper Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 11/17] libxl/arm: Construct ACPI MADT table Shannon Zhao
2016-07-07 16:11   ` Wei Liu
2016-07-07 16:46     ` Julien Grall
2016-07-05  3:12 ` [PATCH v3 12/17] libxl/arm: Construct ACPI FADT table Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 13/17] libxl/arm: Construct ACPI DSDT table Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 14/17] libxl/arm: Factor finalise_one_memory_node as a gerneric function Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 15/17] libxl/arm: Add ACPI module Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 16/17] libxc/xc_dom_core: Copy ACPI tables to guest space Shannon Zhao
2016-07-05  3:12 ` [PATCH v3 17/17] libxl/arm: Initialize domain param HVM_PARAM_CALLBACK_IRQ Shannon Zhao
2016-07-07 16:15   ` Wei Liu
2016-07-07 16:57     ` Julien Grall
2016-07-08  3:41       ` Shannon Zhao
2016-07-08 10:47       ` Wei Liu
2016-07-05 10:32 ` [PATCH v3 00/17] Xen ARM DomU ACPI support Julien Grall
2016-07-05 14:09   ` Shannon Zhao

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=1467688367-17320-7-git-send-email-zhaoshenglong@huawei.com \
    --to=zhaoshenglong@huawei.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=hangaohuai@huawei.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=julien.grall@arm.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=shannon.zhao@linaro.org \
    --cc=sstabellini@kernel.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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).