From patchwork Thu Sep 22 12:52:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 76775 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp14699qgf; Thu, 22 Sep 2016 05:55:16 -0700 (PDT) X-Received: by 10.36.48.195 with SMTP id q186mr10731226itq.111.1474548916284; Thu, 22 Sep 2016 05:55:16 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id u17si1965546itc.119.2016.09.22.05.55.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Sep 2016 05:55:16 -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 1bn3VE-0003z2-Rs; Thu, 22 Sep 2016 12:53:24 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bn3VE-0003yo-8o for xen-devel@lists.xen.org; Thu, 22 Sep 2016 12:53:24 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 8F/70-28857-344D3E75; Thu, 22 Sep 2016 12:53:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRWlGSWpSXmKPExsVSPpHPSdfpyuN wg9UvLC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozHW6UKjqtW3J5U0sB4V6aLkZNDSOAUo8Tm FrMuRi4gew+jxLc1XewgCTYBLYnz03+A2SICshKru+awgxQxC1xnlLjzfhsrSEJYwFVi95LZb CA2i4CqxKrjn8FsXgEPidezfzKB2BICGhIreyewgNicAp4SE46sZ4XY7CGx8spCVoh6QYmTM5 +A1TALSEgcfPGCGaJXUaJt/Uk2CFtS4uCKGywgR0iAXH2xazNUwlRi7tkuxgmMgrOQzJqFZNY CRqZVjBrFqUVlqUW6hhZ6SUWZ6RkluYmZObqGBmZ6uanFxYnpqTmJScV6yfm5mxiB4ckABDsY b24MOMQoycGkJMp7of9xuBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ3seXgHKCRanpqRVpmTnAS IFJS3DwKInwOoOkeYsLEnOLM9MhUqcYFaXEeX+DJARAEhmleXBtsOi8xCgrJczLCHSIEE9Bal FuZgmq/CtGcQ5GJWFesctAU3gy80rgpr8CWswEtHjLzwcgi0sSEVJSDYwR93y0fCf4sDLpOz1 +5543Jynz4g2JCd19C74+XZoUNWOf2Y+KVInt3z5tZt4s0SYty6cc1/hRUUnT1OD1Ex7ezc/m XZ4ddlutN1t+zgeBH3eTu7X37C9KnbdPSHG2NHOO3E3r1BcJ30uCJho0SC/v7dFh/7uD6VRQc 0iGnbD1EuVHD26dLVJiKc5INNRiLipOBAB8+5KtyQIAAA== X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1474548799!34585166!1 X-Originating-IP: [119.145.14.66] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTE5LjE0NS4xNC42NiA9PiA4NTI3\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 62900 invoked from network); 22 Sep 2016 12:53:22 -0000 Received: from szxga03-in.huawei.com (HELO szxga03-in.huawei.com) (119.145.14.66) by server-7.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 22 Sep 2016 12:53:22 -0000 Received: from 172.24.1.47 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.47]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CIG48123; Thu, 22 Sep 2016 20:53:01 +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; Thu, 22 Sep 2016 20:52:52 +0800 From: z00226004 To: Date: Thu, 22 Sep 2016 20:52:21 +0800 Message-ID: <1474548753-12596-5-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1474548753-12596-1-git-send-email-zhaoshenglong@huawei.com> References: <1474548753-12596-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.0A020205.57E3D42E.024A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 73a82860463359e0679d4afe72188903 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 v6 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 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/acpi/actbl1.h | 2 + 2 files changed, 100 insertions(+) diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index 0851411..1dbd7e5 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) + + ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus + + sizeof(struct acpi_madt_generic_distributor); + break; + case XEN_DOMCTL_CONFIG_GIC_V3: + rc = 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; + + 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; } 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 */