From patchwork Thu Sep 29 01:18:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 9355511 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 D50156086A for ; Thu, 29 Sep 2016 01:22:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BED2728E6B for ; Thu, 29 Sep 2016 01:22:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B33562970F; Thu, 29 Sep 2016 01:22:35 +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 51DD228E6B for ; Thu, 29 Sep 2016 01:22:35 +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 1bpQ0q-0001Ui-IB; Thu, 29 Sep 2016 01:19:48 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpQ0p-0001TY-Vt for xen-devel@lists.xen.org; Thu, 29 Sep 2016 01:19:48 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 09/2C-05127-33C6CE75; Thu, 29 Sep 2016 01:19:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCIsWRWlGSWpSXmKPExsVyMfTAZl2jnDf hBs2TDC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyZv5QL5stX3Pj/gamBcYZEFyMnh5DAJEaJ lhsRXYxcHCwC85gljkydzAiSkBDoZ5U4u9wWwo6R2L3+EhuEXS3R/qKNDaJZTWLZ4YXMIM1CA k1MEmeutjGBJNgEdCReTNoJViQiIC1x7fNlRpAiZoEjjBK35p8E6uDgEBawk5i3xxykhkVAVW Lrud3sIDavgI3E/DmXmCCWaUpMn/WaGcTmBIp/aPnFDLHYWmLZt80sExgFFjAyrGLUKE4tKks t0jUy10sqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUwq1kvOz93ECAyregYGxh2MV7f4HWKU5GBS EuXl9HkTLsSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC1ysbKCdYlJqeWpGWmQMMcJi0BAePkgjvq yygNG9xQWJucWY6ROoUozHHlt/X1jJxbJt6by2TEEtefl6qlDjvVZBSAZDSjNI8uEGwyLvEKC slzMvIwMAgxFOQWpSbWYIq/4pRnINRSZg3AeQensy8Erh9r4BOYQI6ZemJFyCnlCQipKQaGAu r1eL+id697zEhpXbDNR/WJVnfGt5NDSn4dLXm9emduw9u2ZCTk1EraFsQHtmfaDtvnd1uvWMT Jyxp+vRlyu6lgXYifwRzzpYV5vwKjXwTpNcoG3RNpHufu/3RIxcVuw4e+vuU/8CTD+LeOxx93 lyq9rL+Jr75+kH1IqVNdpYlWa8v+XhPtVBiKc5INNRiLipOBAA6GFSNtwIAAA== X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-8.tower-206.messagelabs.com!1475111984!61923404!1 X-Originating-IP: [209.85.192.179] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 2904 invoked from network); 29 Sep 2016 01:19:45 -0000 Received: from mail-pf0-f179.google.com (HELO mail-pf0-f179.google.com) (209.85.192.179) by server-8.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 29 Sep 2016 01:19:45 -0000 Received: by mail-pf0-f179.google.com with SMTP id s13so22876341pfd.2 for ; Wed, 28 Sep 2016 18:19:45 -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=4rkykYIJ4a0zFx6rzmNiYGxdjBPR6adxdNHXZoZ/L4o=; b=aiE6cb/ZROZ6NbEGVdyH2SrL0gG+xRlBFXbi5plQPJZtXH1F48Tb3ttOJBV8gPy0SW wvAAmQ254/93hg8/WwkgUWeyEH0gA6d3ooHnGSCOITu6aMBxJubHFWXIYD6zm33rQt5L edHidlbw/yZPynQVminYpZxsb55MQIzv9xlr4= 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=4rkykYIJ4a0zFx6rzmNiYGxdjBPR6adxdNHXZoZ/L4o=; b=F6yt9ko1uHPsJ5ZnAptSCePhP1ix4w5gmGwPk6BVPo9Fx+Ogo7BjV89tZJHdicnON/ yK59RnofX2uIFnxr9VpP9XGjez938L/BHfdER1BYpZZGoCWOhnJt/bDBAmIgp79RrnVj HfIZQl+6yoSdjzC31QPHxZE10lYWs5MnMFg5kQPneqlp03A2DB4XO3fhzt5KCdOJO7dR nzSZwuEKpelpkv/34MEdMSIRhximhzebqZeK/7F/4z7IKbKjyDcREiXbreE0+mYs9MKt 33gknvqN95wZxNSsVMD+RruAAFwzK8C+eCWUezBk3vViUNOArjZWkaatZTWMwrSBQj2P 6Bkg== X-Gm-Message-State: AE9vXwM8SvWccJe86Wr2R2hkeqE0yzkg92yDhuUgqPWLQiSrzowty8lWj2j9UM1sTwRTemPL X-Received: by 10.98.27.195 with SMTP id b186mr61005979pfb.111.1475111984103; Wed, 28 Sep 2016 18:19:44 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Sep 2016 18:19:43 -0700 (PDT) From: Shannon Zhao To: xen-devel@lists.xen.org Date: Wed, 28 Sep 2016 18:18:55 -0700 Message-Id: <20160929011902.7784-10-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 09/16] 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP According to the GIC version, construct the MADT table. Signed-off-by: Shannon Zhao Acked-by: Julien Grall Acked-by: Wei Liu --- tools/libxl/libxl_arm_acpi.c | 84 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index b2136fd..f593dab 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -227,6 +227,89 @@ 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) +{ + int 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 = ACPI_MADT_GICC_SIZE_v5; + 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 = table + ACPI_MADT_GICC_SIZE_v5; + } +} + +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, + libxl_domain_build_info *info, + struct acpitable acpitables[]) +{ + uint64_t offset = acpitables[MADT].addr - GUEST_ACPI_BASE; + void *table = dom->acpi_modules[0].data + offset; + struct acpi_table_madt *madt = table; + int rc = 0; + + switch (info->arch_arm.gic_version) { + case LIBXL_GIC_VERSION_V2: + table += sizeof(struct acpi_table_madt); + make_acpi_madt_gicc(table, info->max_vcpus, GUEST_GICC_BASE); + + table += ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus; + make_acpi_madt_gicd(table, GUEST_GICD_BASE, ACPI_MADT_GIC_VERSION_V2); + break; + case LIBXL_GIC_VERSION_V3: + table += sizeof(struct acpi_table_madt); + make_acpi_madt_gicc(table, info->max_vcpus, 0); + + table += ACPI_MADT_GICC_SIZE_v5 * info->max_vcpus; + 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"); + rc = ERROR_FAIL; + goto out; + } + + make_acpi_header(&madt->header, "APIC", acpitables[MADT].size, 3); + calculate_checksum(madt, offsetof(struct acpi_table_header, checksum), + acpitables[MADT].size); + +out: + return rc; +} + int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, struct xc_dom_image *dom) { @@ -254,6 +337,7 @@ 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, acpitables); out: return rc;