From patchwork Fri Sep 2 02:55:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 75278 Delivered-To: patch@linaro.org Received: by 10.140.29.8 with SMTP id a8csp623905qga; Thu, 1 Sep 2016 19:59:15 -0700 (PDT) X-Received: by 10.202.169.13 with SMTP id s13mr16479630oie.35.1472785140216; Thu, 01 Sep 2016 19:59:00 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id s39si1056858ota.217.2016.09.01.19.59.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Sep 2016 19:59:00 -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 1bfeeq-0006qa-Ah; Fri, 02 Sep 2016 02:56:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfeeo-0006q0-ER for xen-devel@lists.xen.org; Fri, 02 Sep 2016 02:56:42 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 1F/FD-06162-96AE8C75; Fri, 02 Sep 2016 02:56:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVi9XuGg27GqxP hBgvPWFks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBn/P0kWbFKq+HRkH0sD4yKpLkYuDiGBU4wS zW3zmSCc3YwSn1vmMHYxcnKwCehKfNw4hR3EFhGQlVjdNYcdpIhZ4DqjxJ3321hBEsICrhLLZ sxhArFZBFQkGvbNZgOxeQU8JFZvucUCYksIaEis7J0AZnMKeEq8XfUJbKgQUM3jV4+YIOoFJU 7OfAJWwywgIXHwxQtmiF5Fibb1J9kgbEmJgytusIAcIQFy9sTXPewQCVOJ6fdXsU1gFJyFZNY sJLMWMDKtYlQvTi0qSy3SNddLKspMzyjJTczM0TU0MNbLTS0uTkxPzUlMKtZLzs/dxAgMUAYg 2MHY+N3pEKMkB5OSKG/+kxPhQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4jV4C5QSLUtNTK9Iyc 4CxApOW4OBREuE1A0nzFhck5hZnpkOkTjEqSonzvngBlBAASWSU5sG1weLzEqOslDAvI9AhQj wFqUW5mSWo8q8YxTkYlYR5eUHG82TmlcBNfwW0mAloccm14yCLSxIRUlINjE2mE05Y5YRxndk 6gVNH+/SMm5viHt65+nW2/DfxrMWqWo+mvODeujopbwvX0oMrK979idsxYd2bCwEtFnXvZkkE nWbRj3ux9V/BsgNfynoatTXKjZYu+PimxPvRZ+m7Mw59bv6t+NvxXnRE9oTyPZNObHGtO39Xn /Enl6LKFW0Pi7NztD/NZN6sxFKckWioxVxUnAgAmEtDScoCAAA= X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1472784996!41785254!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 61845 invoked from network); 2 Sep 2016 02:56:40 -0000 Received: from szxga01-in.huawei.com (HELO szxga01-in.huawei.com) (58.251.152.64) by server-12.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 2 Sep 2016 02:56:40 -0000 Received: from 172.24.1.60 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.60]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DQM36290; Fri, 02 Sep 2016 10:56:13 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Fri, 2 Sep 2016 10:56:01 +0800 From: Shannon Zhao To: Date: Fri, 2 Sep 2016 10:55:27 +0800 Message-ID: <1472784939-14404-5-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1472784939-14404-1-git-send-email-zhaoshenglong@huawei.com> References: <1472784939-14404-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.0A0B0203.57C8EA4E.00E6, 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: 61e5944c0e07e00628a61ba85a394819 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 v5 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 | 98 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index 0851411..b91f3f6 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -34,12 +34,108 @@ 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_madt_size(libxl__gc *gc, + libxl_domain_build_info *info, + xc_domain_configuration_t *xc_config) +{ + int rc; + + switch (xc_config->gic_version) { + case XEN_DOMCTL_CONFIG_GIC_V2: + rc = 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: + rc = 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; + 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; + + 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); + if (rc < 0) + goto out; + + acpitables[MADT].size = rc; + 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[NUMS]; + + /* convenience aliases */ + xc_domain_configuration_t *xc_config = &state->config; vers = libxl_get_version_info(CTX); if (vers == NULL) { @@ -54,6 +150,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; }