From patchwork Tue Aug 16 10:25:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 73993 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1918388qga; Tue, 16 Aug 2016 03:29:28 -0700 (PDT) X-Received: by 10.107.147.138 with SMTP id v132mr39815756iod.27.1471343368222; Tue, 16 Aug 2016 03:29:28 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 74si5297421ioz.209.2016.08.16.03.29.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Aug 2016 03:29:28 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZbat-0002Ai-Bx; Tue, 16 Aug 2016 10:27:39 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZbas-0002AW-RX for xen-devel@lists.xen.org; Tue, 16 Aug 2016 10:27:38 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id 1C/94-05361-A9AE2B75; Tue, 16 Aug 2016 10:27:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRWlGSWpSXmKPExsVi9XuGg+7MV5v CDW4/5bFY8nExiwOjx9Hdv5kCGKNYM/OS8isSWDM+La0uaFKoODD3HmMD4xOJLkZODiGBU4wS M7+7dTFyAdl7GCWWLLjGDpJgE9CV+LhxCpgtIiArsbprDjtIEbPAdUaJO++3sYIkhAVcJQ5tP cYMYrMIqEo09ewBs3kFPCQ+Pn/CBGJLCGhIrOydwNLFyMHBKeApcW0KG8RiD4nTMxeyQpQLSp yc+YQFxGYWkJA4+OIFM0SrokTb+pNsELakxMEVN1hAbpAAObpv5lwWiISpxJYH69gnMArOQjJ rFpJZCxiZVjFqFKcWlaUW6Rqa6CUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCYV6yXn525iBIYn AxDsYLy+MeAQoyQHk5Io78yJG8OF+JLyUyozEosz4otKc1KLDzHKcHAoSfBeebEpXEiwKDU9t SItMwcYKTBpCQ4eJRFe05dAad7igsTc4sx0iNQpRkUpcV45kIQASCKjNA+uDRadlxhlpYR5GY EOEeIpSC3KzSxBlX/FKM7BqCTMawYyhSczrwRu+iugxUxAi/WlN4AsLklESEk1MJZ1uHA8WN8 uw+//6v1FVluRm4EhDc8KK18Xn7vp1SIv7PODgzHfYdmjw84rd0/zTGSc+/LdrMzsaMVZ+SGZ U5c41Hef8JzVE5Ss7Zd2eqvctLmPLGvFLyveMHrStmV+nZX8/+obVpp72RZUJJ9tXHVkybbZC kunzs7Y9ztxz04ttVd3hT9Ob1BiKc5INNRiLipOBABFxOMkyQIAAA== X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1471343252!22580631!1 X-Originating-IP: [58.251.152.64] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32510 invoked from network); 16 Aug 2016 10:27:36 -0000 Received: from szxga01-in.huawei.com (HELO szxga01-in.huawei.com) (58.251.152.64) by server-4.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 16 Aug 2016 10:27:36 -0000 Received: from 172.24.1.36 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.36]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DPP02647; Tue, 16 Aug 2016 18:26:19 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Tue, 16 Aug 2016 18:25:34 +0800 From: Shannon Zhao To: Date: Tue, 16 Aug 2016 18:25:01 +0800 Message-ID: <1471343113-10652-5-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1471343113-10652-1-git-send-email-zhaoshenglong@huawei.com> References: <1471343113-10652-1-git-send-email-zhaoshenglong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.57B2EA4E.0034, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 3ef842ba85343a9688b765afc4914721 Cc: 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: [Xen-devel] [PATCH v4 04/16] libxl/arm: Estimate the size of ACPI tables X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" From: Shannon Zhao Estimate the size of ACPI tables and reserve a memory map space for ACPI tables. Signed-off-by: Shannon Zhao --- tools/libxl/libxl_arm_acpi.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index 087d028..6be9eb0 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -33,12 +33,95 @@ 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; + int rc = 0; + + 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; + + 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"); + rc = ERROR_FAIL; + 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); + +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[NUMS]; + + /* convenience aliases */ + xc_domain_configuration_t *xc_config = &state->config; vers = libxl_get_version_info(CTX); if (vers == NULL) { @@ -53,6 +136,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; }