From patchwork Thu Sep 29 01:18:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 77108 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp79896qgf; Wed, 28 Sep 2016 18:22:17 -0700 (PDT) X-Received: by 10.107.142.147 with SMTP id q141mr162025iod.67.1475112137265; Wed, 28 Sep 2016 18:22:17 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id f82si13202748ita.115.2016.09.28.18.22.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Sep 2016 18:22:17 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.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 1bpQ0i-0001LC-6s; Thu, 29 Sep 2016 01:19:40 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpQ0h-0001Kk-CI for xen-devel@lists.xen.org; Thu, 29 Sep 2016 01:19:39 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 66/DC-04595-A2C6CE75; Thu, 29 Sep 2016 01:19:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRWlGSWpSXmKPExsVyMfTAGl3NnDf hBvNOWlks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBmds1ewFjxRrpjQ+Iu5gXGbdBcjF4eQwCRG ic6dM9lBHBaBecwSp79NYwZxJAT6WSWal01m7WLkAHJiJG4+F+5i5AQyqyR+Pj7ODGILCahJL Du8kBliUhOTxIVbs9hAEmwCOhIvJu0Es0UEpCWufb7MCFLELHCEUeLW/JNg3cICrhKzjjcygd gsAqoSWxoawRp4Bawlerc9Z4PYpikxfdZrsHpOARuJDy2/oDZbSyz7tpllAqPAAkaGVYwaxal FZalFusaGeklFmekZJbmJmTm6hgZmermpxcWJ6ak5iUnFesn5uZsYgcHFAAQ7GJsWBR5ilORg UhLl5fR5Ey7El5SfUpmRWJwRX1Sak1p8iFGGg0NJgjc8CygnWJSanlqRlpkDDHOYtAQHj5II7 45MoDRvcUFibnFmOkTqFKMxx5bf19YycWybem8tkxBLXn5eqpQ4bwLIJAGQ0ozSPLhBsPi7xC grJczLCHSaEE9BalFuZgmq/CtGcQ5GJWHetSBTeDLzSuD2vQI6hQnolKUnXoCcUpKIkJJqYMy 1neX5R/Pbi4TzD/QErr/h2vix4234ZLvCr/9//GauEvolpNPU05CjnVD44b/NdpMH8qlhxuUi eg+bL9Tpimoqzri21+Bdz9fe2Ze5O7XaFHmv19wLtP09n786gt36oeOuPY621pYC9SaiYadVQ 0I5Pwez7m8KZZrQFh6iL+Ef7zdFZ0qiEktxRqKhFnNRcSIAen3N6LoCAAA= X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-11.tower-21.messagelabs.com!1475111976!35479141!1 X-Originating-IP: [209.85.192.172] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20230 invoked from network); 29 Sep 2016 01:19:37 -0000 Received: from mail-pf0-f172.google.com (HELO mail-pf0-f172.google.com) (209.85.192.172) by server-11.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 29 Sep 2016 01:19:37 -0000 Received: by mail-pf0-f172.google.com with SMTP id l25so22857624pfb.1 for ; Wed, 28 Sep 2016 18:19:37 -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=m6BLOUojlnjHkZbXL8KgxlBu00yjs1GGiVpPl+j2pyU=; b=eW98FPT6l0l572+vesm77Whk166uWn0DulJ352Sy9rr1nBC+bVquHNNRYR8njvn2Ay vzAzucK19q75l45VTLJ3npu2QxOqGwhHKDCXXPgZd+K4LIBn5d1MnOvTUAz4YudOzwtA hRopCJFmHPGG/yjWKKQ4Fs2NofRhNmGCDzRAU= 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=m6BLOUojlnjHkZbXL8KgxlBu00yjs1GGiVpPl+j2pyU=; b=gjGPkAEiBHwPORpehESq6JReRfXxK4icY/MqqLbv5o3CM8BuX0wL6TTj5+sfsreA/K WHEeQoCkJuTGiv1M/SFucGY92G5A95YOAuh0JU0mI4aAKPtNtgXoIMQbPYmK9AnDSrJT 9ciAT0wP79MZLcDUTlFykpsx5BDi1ZlcbbsaCh2cGaaM4muZMjtMh2bFjsgH3JQdjkLM YlK5T/Q9wWOTLQwTOiTkFvov1wKo4HBOeM314cNRfnbMKWdj8/5omOt5Q2D3ITIpTj3D FdrVhypuWjkbasQm3tiDRrfLeg9l/hckmTZgo3eyyYJ9HmnJdmhDq4iJ4YWcXBLkbjV/ zwSw== X-Gm-Message-State: AE9vXwNq8MExGQbLyA9y0PPBF3bmO1GN3ttDQeY4iM5ZFsBITuq6qrISsliTIHLnXNm8NHr5 X-Received: by 10.98.204.85 with SMTP id a82mr60762615pfg.180.1475111976410; Wed, 28 Sep 2016 18:19:36 -0700 (PDT) Received: from HZA160860128-A.china.huawei.com ([67.238.99.186]) by smtp.gmail.com with ESMTPSA id wd7sm15228744pab.2.2016.09.28.18.19.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Sep 2016 18:19:35 -0700 (PDT) From: Shannon Zhao To: xen-devel@lists.xen.org Date: Wed, 28 Sep 2016 18:18:50 -0700 Message-Id: <20160929011902.7784-5-shannon.zhao@linaro.org> X-Mailer: git-send-email 2.10.0.windows.1 In-Reply-To: <20160929011902.7784-1-shannon.zhao@linaro.org> References: <20160929011902.7784-1-shannon.zhao@linaro.org> 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 v8 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" 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 | 95 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/acpi/actbl1.h | 2 + 2 files changed, 97 insertions(+) diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index 06dff5f..bc9ab84 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -34,11 +34,104 @@ 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, + size_t *size) +{ + int rc = 0; + + switch (info->arch_arm.gic_version) { + case LIBXL_GIC_VERSION_V2: + *size = sizeof(struct acpi_table_madt) + + ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus + + sizeof(struct acpi_madt_generic_distributor); + break; + case LIBXL_GIC_VERSION_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__allocate_acpi_tables(libxl__gc *gc, + libxl_domain_build_info *info, + struct xc_dom_image *dom, + 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, &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, struct xc_dom_image *dom) { const libxl_version_info *vers; int rc = 0; + struct acpitable acpitables[MAX_TABLE_NUMS]; vers = libxl_get_version_info(CTX); if (vers == NULL) { @@ -53,6 +146,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__allocate_acpi_tables(gc, info, dom, 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 */