From patchwork Tue Sep 27 15:20:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 9352095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CA69600CB for ; Tue, 27 Sep 2016 15:24:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DF0628ABD for ; Tue, 27 Sep 2016 15:24:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 628DB291EE; Tue, 27 Sep 2016 15:24:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3855828ABD for ; Tue, 27 Sep 2016 15:24:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bouCM-0004Zy-2i; Tue, 27 Sep 2016 15:21:34 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bouCL-0004Zr-O2 for xen-devel@lists.xen.org; Tue, 27 Sep 2016 15:21:33 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id 50/73-01957-C7E8AE75; Tue, 27 Sep 2016 15:21:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRWlGSWpSXmKPExsVyMfSOrm5N36t wgzuHeC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozmlqcsBWvUKjpO7WZrYGyT7WLk4hASmMAo 8WnTZDYQh0VgHrPEl5cLWUAcCYF+VokTn86xdjFyAjkxEs8X32CEsKskJjZdZQexhQTUJJYdX sgMMaqRSaLlwF9mkASbgI7Ei0k72UBsEQFpiWufLzOCFDELHGGUuDX/JFiRsICrxNaPq8BsFg FVif9tnUwgNq+AjcTp9qlQ2zQlps96DVbDKeApcfD3e6jNHhIL9vWyT2AUWMDIsIpRvTi1qCy 1SNdML6koMz2jJDcxM0fX0MBULze1uDgxPTUnMalYLzk/dxMjMLgYgGAH49QG50OMkhxMSqK8 Gu2vwoX4kvJTKjMSizPii0pzUosPMcpwcChJ8P7oAcoJFqWmp1akZeYAwxwmLcHBoyTC69oLl OYtLkjMLc5Mh0idYjTm2PL72lomjm1T761lEmLJy89LlRLn/Q8ySQCkNKM0D24QLP4uMcpKCf MyAp0mxFOQWpSbWYIq/4pRnINRSZg3FGQhT2ZeCdy+V0CnMAGdsvTEC5BTShIRUlINjGy2luI ZM9SuTru+vCHQer6DJ+NL6xvfjCYGnou9tiYqUmx38yWeA0GdH3/65ahqh0bs1/to4p8rrzLZ eNl9Vy6xnPoz8/QCMvtFzyWvuZNcsGXzAZ47VRc/7v/2x+qfm9R7t4llMzQLPCq3T8wxk5602 TL7y7r0wtU1D/lDttr5Pt9xVeStqRJLcUaioRZzUXEiAMnNV6e6AgAA X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-6.tower-206.messagelabs.com!1474989688!61536001!1 X-Originating-IP: [209.85.220.45] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37903 invoked from network); 27 Sep 2016 15:21:30 -0000 Received: from mail-pa0-f45.google.com (HELO mail-pa0-f45.google.com) (209.85.220.45) by server-6.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 27 Sep 2016 15:21:30 -0000 Received: by mail-pa0-f45.google.com with SMTP id gp7so6637822pac.1 for ; Tue, 27 Sep 2016 08:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0BeCw1GH9kZ0zILLBu8eor/9LM545kMOsvbe7q9HNFE=; b=GV+FOGciyYpNeWt1aGvevwx5Aw/se+gc9RM5AE8MnkubPlsc4206mMTXHVjjmCxtm/ lq/WQ5+mGVMOkt8gufYp+1KkjVrofMCg3g9H+7LRhj2bIZyxf9JZOtC4byGNgqfaRmR0 xYFYZcqxDQNgVDZU9Ks9hWYwQjdRBjcEWx+yU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0BeCw1GH9kZ0zILLBu8eor/9LM545kMOsvbe7q9HNFE=; b=WVe7lO/ZVUPwMaUM9BFZ3AtJp38g1eZiITizzP1/g5qEsoKrfbRsZntbaFe6oAm5MG zeZM5TbbjywekVPiNtaY2zT2DNM4G74qAkRD1BIEYv7ZK362rCDh31WEBbJmn8W0sJFf JzxG8mca/xyKlZis9KDpVCtJvIfglxPep0EIQqqUxyxXCIhSbiI07fN84Y4g43F4BXLn UEK2R1DB91RAQH8SfyJMs2Fqr79San0v4l3Yu9nT8OjW7X0Q7bxE+AsQthlWi98+0WT8 JLe+f/LHzaMu4DXUX1aWRH1UegmSSAfLvSFFFjpKPJ0UPHT8BHybZroqwcs29V2+mgDt P1og== X-Gm-Message-State: AE9vXwO0Xiq1CrCwxUGj0KNnCZAj2oYM22jyyJkM7/UovUgjmPEJ0f6I8PXnzXc3I+Ice6+C X-Received: by 10.66.124.198 with SMTP id mk6mr48408129pab.74.1474989688280; Tue, 27 Sep 2016 08:21:28 -0700 (PDT) Received: from HZA160860128-A.china.huawei.com ([67.238.99.186]) by smtp.gmail.com with ESMTPSA id c28sm5804809pfj.6.2016.09.27.08.21.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Sep 2016 08:21:27 -0700 (PDT) From: Shannon Zhao To: xen-devel@lists.xen.org Date: Tue, 27 Sep 2016 08:20:39 -0700 Message-Id: <20160927152039.52000-1-shannon.zhao@linaro.org> X-Mailer: git-send-email 2.10.0.windows.1 In-Reply-To: <1474548753-12596-5-git-send-email-zhaoshenglong@huawei.com> References: <1474548753-12596-5-git-send-email-zhaoshenglong@huawei.com> Cc: sstabellini@kernel.org, wei.liu2@citrix.com, ian.jackson@eu.citrix.com, julien.grall@arm.com, Shannon Zhao , zhaoshenglong@huawei.com, boris.ostrovsky@oracle.com Subject: [Xen-devel] [PATCH v7 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 | 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 */