From: Shannon Zhao <shannon.zhao@linaro.org>
To: xen-devel@lists.xen.org
Cc: sstabellini@kernel.org, wei.liu2@citrix.com,
ian.jackson@eu.citrix.com, julien.grall@arm.com,
Shannon Zhao <shannon.zhao@linaro.org>,
zhaoshenglong@huawei.com, boris.ostrovsky@oracle.com
Subject: [PATCH v7 04/16] libxl/arm: Estimate the size of ACPI tables
Date: Tue, 27 Sep 2016 08:20:39 -0700 [thread overview]
Message-ID: <20160927152039.52000-1-shannon.zhao@linaro.org> (raw)
In-Reply-To: <1474548753-12596-5-git-send-email-zhaoshenglong@huawei.com>
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 | 100 +++++++++++++++++++++++++++++++++++++++++++
xen/include/acpi/actbl1.h | 2 +
2 files changed, 102 insertions(+)
diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 0851411..33a25ff 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -34,12 +34,110 @@ extern const unsigned char dsdt_anycpu_arm[];
_hidden
extern const int dsdt_anycpu_arm_len;
+enum {
+ RSDP,
+ XSDT,
+ GTDT,
+ MADT,
+ FADT,
+ DSDT,
+ MAX_TABLE_NUMS,
+};
+
+struct acpitable {
+ uint64_t addr;
+ size_t size;
+};
+
+static int libxl__estimate_madt_size(libxl__gc *gc,
+ const libxl_domain_build_info *info,
+ const xc_domain_configuration_t *xc_config,
+ size_t *size)
+{
+ int rc = 0;
+
+ switch (xc_config->gic_version) {
+ case XEN_DOMCTL_CONFIG_GIC_V2:
+ *size = sizeof(struct acpi_table_madt) +
+ ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus +
+ sizeof(struct acpi_madt_generic_distributor);
+ break;
+ case XEN_DOMCTL_CONFIG_GIC_V3:
+ *size = sizeof(struct acpi_table_madt) +
+ ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus +
+ sizeof(struct acpi_madt_generic_distributor) +
+ sizeof(struct acpi_madt_generic_redistributor);
+ break;
+ default:
+ LOG(ERROR, "Unknown GIC version");
+ rc = ERROR_FAIL;
+ break;
+ }
+
+ return rc;
+}
+
+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[])
+{
+ int rc;
+ size_t size;
+
+ acpitables[RSDP].addr = GUEST_ACPI_BASE;
+ acpitables[RSDP].size = sizeof(struct acpi_table_rsdp);
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[RSDP].size, 3);
+
+ acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+ /*
+ * 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->acpi_modules[0].length += ROUNDUP(acpitables[XSDT].size, 3);
+
+ acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+ acpitables[GTDT].size = sizeof(struct acpi_table_gtdt);
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[GTDT].size, 3);
+
+ acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+
+ rc = libxl__estimate_madt_size(gc, info, xc_config, &size);
+ if (rc < 0)
+ goto out;
+
+ acpitables[MADT].size = size;
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[MADT].size, 3);
+
+ acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+ acpitables[FADT].size = sizeof(struct acpi_table_fadt);
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[FADT].size, 3);
+
+ acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpi_modules[0].length;
+ acpitables[DSDT].size = dsdt_anycpu_arm_len;
+ dom->acpi_modules[0].length += ROUNDUP(acpitables[DSDT].size, 3);
+
+ assert(dom->acpi_modules[0].length <= GUEST_ACPI_SIZE);
+ dom->acpi_modules[0].data = libxl__zalloc(gc, dom->acpi_modules[0].length);
+
+ rc = 0;
+out:
+ return rc;
+}
+
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 = 0;
+ struct acpitable acpitables[MAX_TABLE_NUMS];
+
+ /* convenience aliases */
+ xc_domain_configuration_t *xc_config = &state->config;
vers = libxl_get_version_info(CTX);
if (vers == NULL) {
@@ -54,6 +152,8 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
dom->acpi_modules[0].length = 0;
dom->acpi_modules[0].guest_addr_out = GUEST_ACPI_BASE;
+ rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables);
+
out:
return rc;
}
diff --git a/xen/include/acpi/actbl1.h b/xen/include/acpi/actbl1.h
index ed5cd2d..e199136 100644
--- a/xen/include/acpi/actbl1.h
+++ b/xen/include/acpi/actbl1.h
@@ -786,6 +786,8 @@ struct acpi_madt_generic_interrupt {
u8 reserved2[3];
};
+#define ACPI_MADT_GICC_SIZE_v5 76
+
/* Masks for Flags field above */
/* ACPI_MADT_ENABLED (1) Processor is usable if set */
--
2.10.0.windows.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-09-27 15:20 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 12:52 [PATCH v6 00/16] Xen ARM DomU ACPI support z00226004
2016-09-22 12:52 ` [PATCH v6 01/16] tools/libxl: Add an unified configuration option for ACPI z00226004
2016-09-22 12:52 ` [PATCH v6 02/16] libxl/arm: prepare for constructing ACPI tables z00226004
2016-09-22 14:13 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 03/16] libxl/arm: Generate static ACPI DSDT table z00226004
2016-09-22 12:52 ` [PATCH v6 04/16] libxl/arm: Estimate the size of ACPI tables z00226004
2016-09-22 14:21 ` Wei Liu
2016-09-27 15:20 ` Shannon Zhao [this message]
2016-09-22 12:52 ` [PATCH v6 05/16] libxl/arm: Construct ACPI RSDP table z00226004
2016-09-22 14:14 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 06/16] libxl/arm: Construct ACPI XSDT table z00226004
2016-09-22 14:14 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 07/16] libxl/arm: Construct ACPI GTDT table z00226004
2016-09-22 14:14 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 08/16] libxl/arm: Factor MPIDR computing codes out as a helper z00226004
2016-09-22 14:14 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 09/16] libxl/arm: Construct ACPI MADT table z00226004
2016-09-22 14:14 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 10/16] libxl/arm: Construct ACPI FADT table z00226004
2016-09-22 14:14 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 11/16] libxl/arm: Construct ACPI DSDT table z00226004
2016-09-22 14:15 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 12/16] libxl/arm: Factor finalise_one_memory_node as a gerneric function z00226004
2016-09-22 14:15 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 13/16] libxl/arm: Add ACPI module z00226004
2016-09-22 14:15 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 14/16] public/hvm/params.h: Add macros for HVM_PARAM_CALLBACK_TYPE_PPI z00226004
2016-09-22 14:44 ` Julien Grall
2016-09-22 15:00 ` Jan Beulich
2016-09-26 19:45 ` Shannon Zhao
2016-09-27 8:01 ` Jan Beulich
2016-09-27 15:27 ` [PATCH v7 " Shannon Zhao
2016-09-28 10:55 ` Jan Beulich
2016-09-22 12:52 ` [PATCH v6 15/16] libxl/arm: Initialize domain param HVM_PARAM_CALLBACK_IRQ z00226004
2016-09-22 14:16 ` Wei Liu
2016-09-22 12:52 ` [PATCH v6 16/16] libxl/arm: Add the size of ACPI tables to maxmem z00226004
2016-09-22 14:10 ` Wei Liu
2016-09-22 14:32 ` Wei Liu
2016-09-26 7:08 ` Shannon Zhao
2016-09-26 9:05 ` Wei Liu
2016-09-26 18:30 ` Shannon Zhao
2016-09-27 9:30 ` Wei Liu
2016-09-26 21:54 ` Shannon Zhao
2016-09-27 9:41 ` Wei Liu
2016-09-27 16:01 ` Shannon Zhao
2016-09-27 16:35 ` Wei Liu
2016-09-27 18:43 ` Shannon Zhao
2016-09-28 10:00 ` Wei Liu
2016-09-28 13:11 ` Shannon Zhao
2016-09-28 13:17 ` Wei Liu
2016-09-28 17:52 ` Julien Grall
2016-09-22 13:27 ` [PATCH v6 00/16] Xen ARM DomU ACPI support Julien Grall
2016-09-22 13:32 ` Shannon Zhao
2016-09-22 13:37 ` Julien Grall
2016-09-22 13:38 ` Shannon Zhao
2016-09-22 14:27 ` Julien Grall
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=20160927152039.52000-1-shannon.zhao@linaro.org \
--to=shannon.zhao@linaro.org \
--cc=boris.ostrovsky@oracle.com \
--cc=ian.jackson@eu.citrix.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
--cc=zhaoshenglong@huawei.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).