From patchwork Tue Jul 5 03:12:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 71373 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp91322qgy; Mon, 4 Jul 2016 20:17:14 -0700 (PDT) X-Received: by 10.107.16.142 with SMTP id 14mr10680338ioq.142.1467688632095; Mon, 04 Jul 2016 20:17:12 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id h131si1586823ioa.82.2016.07.04.20.17.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jul 2016 20:17:12 -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 1bKGoz-0008WA-WD; Tue, 05 Jul 2016 03:14:49 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bKGoz-0008Vc-CS for xen-devel@lists.xen.org; Tue, 05 Jul 2016 03:14:49 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 86/3A-11548-8262B775; Tue, 05 Jul 2016 03:14:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRWlGSWpSXmKPExsVSPpHPUVdDrTr c4Md1HoslHxezODB6HN39mymAMYo1My8pvyKBNePX3k0sBQeVK5ob1rE3MF6U7mLk4hASOMUo 0b3/JyOEs5tRYuest0AOJwebgK7Ex41T2EFsEQFZidVdc8BsZoEPjBKnZkt0MXJwCAu4SuzZy wQSZhFQkfj14Q+YzSvgITH34VYWEFtCQENiZe8EMJtTwFPi600IWwiopv/AelaIekGJkzOfsE CMl5A4+OIFM0SvokTb+pNsELakxMEVN1hA7pQAOfpiyx9GiISpxLXVS5gnMArOQjJrFpJZCxi ZVjGqF6cWlaUW6RrpJRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhXrJefnbmIEhicDEOxgXPbX 6RCjJAeTkijvq39V4UJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeEVVq8OFBItS01Mr0jJzgJECk 5bg4FES4VUCSfMWFyTmFmemQ6ROMSpKifMKgiQEQBIZpXlwbbDovMQoKyXMywh0iBBPQWpRbm YJqvwrRnEORiVhXk2QKTyZeSVw018BLWYCWswaWw6yuCQRISXVwNiWvKFj7l6rD+2bbsskX+n mlCsr+PRz5c2fV4QjvbM2VIgsmCOdvGPBBQHV5XN1utpm/5+RaTxpJduUUOEuV/2ilBfvIzmj nX7HPjm3va5G68KzxCdF21xWGBZMlnGKS5m6eH3ZnwC+lofpu+86Pu/svtT2IU3oz5z99fv+7 vfIVNn0totLS0aJpTgj0VCLuag4EQAJZEHjyQIAAA== X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1467688485!22179305!1 X-Originating-IP: [119.145.14.65] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTE5LjE0NS4xNC42NSA9PiA3NzQ2Mw==\n X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5378 invoked from network); 5 Jul 2016 03:14:47 -0000 Received: from szxga02-in.huawei.com (HELO szxga02-in.huawei.com) (119.145.14.65) by server-10.tower-21.messagelabs.com with SMTP; 5 Jul 2016 03:14:47 -0000 Received: from 172.24.1.47 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DJT72000; Tue, 05 Jul 2016 11:14:09 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Tue, 5 Jul 2016 11:13:58 +0800 From: Shannon Zhao To: Date: Tue, 5 Jul 2016 11:12:36 +0800 Message-ID: <1467688367-17320-7-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1467688367-17320-1-git-send-email-zhaoshenglong@huawei.com> References: <1467688367-17320-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.577B2601.008B, 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: c64db87714da29e9e48a3494b3f9a493 Cc: hangaohuai@huawei.com, 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 v3 06/17] 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 +++++++++++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 4 ++ 2 files changed, 89 insertions(+) diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index d1c066d..7a59126 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -33,11 +33,92 @@ 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; + + acpitables[RSDP].addr = GUEST_ACPI_BASE; + acpitables[RSDP].size = sizeof(struct acpi_table_rsdp); + dom->acpitable_size += ROUNDUP(acpitables[RSDP].size, 3); + + acpitables[XSDT].addr = GUEST_ACPI_BASE + dom->acpitable_size; + /* + * 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->acpitable_size += ROUNDUP(acpitables[XSDT].size, 3); + + acpitables[GTDT].addr = GUEST_ACPI_BASE + dom->acpitable_size; + acpitables[GTDT].size = sizeof(struct acpi_table_gtdt); + dom->acpitable_size += ROUNDUP(acpitables[GTDT].size, 3); + + acpitables[MADT].addr = GUEST_ACPI_BASE + dom->acpitable_size; + + 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"); + return ERROR_FAIL; + } + + acpitables[MADT].size = size; + dom->acpitable_size += ROUNDUP(acpitables[MADT].size, 3); + + acpitables[FADT].addr = GUEST_ACPI_BASE + dom->acpitable_size; + acpitables[FADT].size = sizeof(struct acpi_table_fadt); + dom->acpitable_size += ROUNDUP(acpitables[FADT].size, 3); + + acpitables[DSDT].addr = GUEST_ACPI_BASE + dom->acpitable_size; + acpitables[DSDT].size = dsdt_anycpu_arm_len; + dom->acpitable_size += ROUNDUP(acpitables[DSDT].size, 3); + + assert(dom->acpitable_size <= GUEST_ACPI_SIZE); + dom->acpitable_blob = libxl__zalloc(gc, dom->acpitable_size); + + return 0; +} + 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; + struct acpitable acpitables[NUMS]; + + /* convenience aliases */ + xc_domain_configuration_t *xc_config = &state->config; vers = libxl_get_version_info(CTX); if (vers == NULL) @@ -49,6 +130,10 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, dom->acpitable_blob = NULL; dom->acpitable_size = 0; + rc = libxl__estimate_acpi_size(gc, info, dom, xc_config, acpitables); + if (rc) + return rc; + return 0; } diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 4a49254..008a2a0 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -406,6 +406,10 @@ typedef uint64_t xen_callback_t; #define GUEST_GICV3_GICR0_BASE 0x03020000ULL /* vCPU0 - vCPU127 */ #define GUEST_GICV3_GICR0_SIZE 0x01000000ULL +/* ACPI tables physical address */ +#define GUEST_ACPI_BASE 0x20000000ULL +#define GUEST_ACPI_SIZE 0x00200000ULL + /* * 16MB == 4096 pages reserved for guest to use as a region to map its * grant table in.