From patchwork Tue Jul 5 03:12:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 71385 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp94038qgy; Mon, 4 Jul 2016 20:28:15 -0700 (PDT) X-Received: by 10.36.101.6 with SMTP id u6mr10814591itb.8.1467688821426; Mon, 04 Jul 2016 20:20:21 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id t15si1526266ioi.245.2016.07.04.20.20.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jul 2016 20:20:21 -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 1bKGsN-0001gn-VV; Tue, 05 Jul 2016 03:18:19 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bKGsM-0001fp-Lb for xen-devel@lists.xen.org; Tue, 05 Jul 2016 03:18:18 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id FA/D4-32245-9F62B775; Tue, 05 Jul 2016 03:18:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVSPpHPUfenWnW 4wdolahZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a/D/tYC7bJVyy4tYSxgXGBRBcjF4eQwClG id53fxghnN2MEjsmLmPrYuTkYBPQlfi4cQo7iC0iICuxumsOmM0s8IFR4tRsCRBbWMBOov/sP VYQm0VARaLp43ZGEJtXwFPi1o5GMFtCQENiZe8EFhCbEyj+9SaELSTgIdF/YD0rRL2gxMmZT1 gg5ktIHHzxghmiV1Gibf1JNghbUuLgihssIIdKgFzdOuc71AJTiUm9HxgnMArOQjJrFpJZCxi ZVjGqF6cWlaUW6ZroJRVlpmeU5CZm5ugaGhjr5aYWFyemp+YkJhXrJefnbmIEBigDEOxgbPzi dIhRkoNJSZT31b+qcCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvA7AgBcSLEpNT61Iy8wBxgpMW oKDR0mE95YqUJq3uCAxtzgzHSJ1ilFRSpyXEaRPACSRUZoH1waLz0uMslLCvIxAhwjxFKQW5W aWoMq/YhTnYFQS5g0CmcKTmVcCN/0V0GImoMWsseUgi0sSEVJSDYyG1pNCrrZskip4uDeVJfH LjVWrV+tG7g33sMu8/GqtwLvwpD+3dF493lPwsFB30rK/9mkKYidLd8//MzNNplH94E8d4+um 5b7Wmodj+ZPN9p38npJYoHeMLVb+YXN/Qtsj2U1XPUpz35oFL7luPquuWb3wQuzko3xPX7/ar r0k8Fhuu8HJ4GdKLMUZiYZazEXFiQCvcz0EygIAAA== X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1467688692!48849589!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 28727 invoked from network); 5 Jul 2016 03:18:16 -0000 Received: from unknown (HELO szxga02-in.huawei.com) (119.145.14.65) by server-14.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 5 Jul 2016 03:18:16 -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 DJT72013; Tue, 05 Jul 2016 11:14:14 +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:14:02 +0800 From: Shannon Zhao To: Date: Tue, 5 Jul 2016 11:12:41 +0800 Message-ID: <1467688367-17320-12-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.577B2607.0009, 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: 6844348ff5ef4e8041cf2bd00abca30d 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 11/17] libxl/arm: Construct ACPI MADT table 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 According to the GIC version, construct the MADT table. Signed-off-by: Shannon Zhao --- tools/libxl/libxl_arm_acpi.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index c2599b7..96ce605 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -199,6 +199,86 @@ static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom, acpitables[GTDT].size); } +static void make_acpi_madt_gicc(void *table, int nr_cpus, uint64_t gicc_base) +{ + uint32_t i; + struct acpi_madt_generic_interrupt *gicc = table; + + for (i = 0; i < nr_cpus; i++) { + gicc->header.type = ACPI_MADT_TYPE_GENERIC_INTERRUPT; + gicc->header.length = sizeof(*gicc); + gicc->base_address = gicc_base; + gicc->cpu_interface_number = i; + gicc->arm_mpidr = libxl__compute_mpdir(i); + gicc->uid = i; + gicc->flags = ACPI_MADT_ENABLED; + gicc++; + } +} + +static void make_acpi_madt_gicd(void *table, uint64_t gicd_base, + uint8_t gic_version) +{ + struct acpi_madt_generic_distributor *gicd = table; + + gicd->header.type = ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR; + gicd->header.length = sizeof(*gicd); + gicd->base_address = gicd_base; + /* This version field has no meaning before ACPI 5.1 errata. */ + gicd->version = gic_version; +} + +static void make_acpi_madt_gicr(void *table, uint64_t gicr_base, + uint64_t gicr_size) +{ + struct acpi_madt_generic_redistributor *gicr = table; + + gicr->header.type = ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR; + gicr->header.length = sizeof(*gicr); + gicr->base_address = gicr_base; + gicr->length = gicr_size; +} + +static int make_acpi_madt(libxl__gc *gc, struct xc_dom_image *dom, int nr_cpus, + xc_domain_configuration_t *xc_config, + struct acpitable acpitables[]) +{ + uint64_t offset = acpitables[MADT].addr - GUEST_ACPI_BASE; + struct acpi_table_madt *madt = dom->acpitable_blob + offset; + void *table = dom->acpitable_blob + offset; + + switch (xc_config->gic_version) { + case XEN_DOMCTL_CONFIG_GIC_V2: + table += sizeof(struct acpi_table_madt); + make_acpi_madt_gicc(table, nr_cpus, GUEST_GICC_BASE); + + table += sizeof(struct acpi_madt_generic_interrupt) * nr_cpus; + make_acpi_madt_gicd(table, GUEST_GICD_BASE, ACPI_MADT_GIC_VERSION_V2); + break; + case XEN_DOMCTL_CONFIG_GIC_V3: + table += sizeof(struct acpi_table_madt); + make_acpi_madt_gicc(table, nr_cpus, 0); + + table += sizeof(struct acpi_madt_generic_interrupt) * nr_cpus; + make_acpi_madt_gicd(table, GUEST_GICV3_GICD_BASE, + ACPI_MADT_GIC_VERSION_V3); + + table += sizeof(struct acpi_madt_generic_distributor); + make_acpi_madt_gicr(table, GUEST_GICV3_GICR0_BASE, + GUEST_GICV3_GICR0_SIZE); + break; + default: + LOG(ERROR, "Unknown GIC version"); + return ERROR_FAIL; + } + + make_acpi_header(&madt->header, "APIC", acpitables[MADT].size, 3); + calculate_checksum(madt, offsetof(struct acpi_table_header, checksum), + acpitables[MADT].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) @@ -227,6 +307,9 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, make_acpi_rsdp(gc, dom, acpitables); make_acpi_xsdt(gc, dom, acpitables); make_acpi_gtdt(gc, dom, acpitables); + rc = make_acpi_madt(gc, dom, info->max_vcpus, xc_config, acpitables); + if (rc) + return rc; return 0; }