From patchwork Thu Sep 22 12:52:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 76776 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp14701qgf; Thu, 22 Sep 2016 05:55:16 -0700 (PDT) X-Received: by 10.107.201.20 with SMTP id z20mr2618750iof.90.1474548916319; 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 m184si1846538ioe.181.2016.09.22.05.55.12 (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 1bn3VF-0003zF-2h; Thu, 22 Sep 2016 12:53:25 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bn3VE-0003yp-Ea for xen-devel@lists.xen.org; Thu, 22 Sep 2016 12:53:24 +0000 Received: from [85.158.139.211] by server-15.bemta-5.messagelabs.com id 2F/BF-01343-344D3E75; Thu, 22 Sep 2016 12:53:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBIsWRWlGSWpSXmKPExsVSPpHPSdf5yuN wgwkHWCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oyZT96zFTyUr1j0fTJbA+MeiS5GLg4hgTOM Eg8m72PvYuQEcvYwSrxYngJiswloSZyf/gMsLiIgK7G6aw47SAOzwHVGiTvvt7GCJIQF7CQOt XeBFbEIqEoc//mJGcTmFfCUuHP7PlhcQkBDYmXvBBYQmxMoPuHIelaIZR4SK68sZIWoF5Q4Of MJWA2zgITEwRcvmCF6FSXa1p9kg7AlJQ6uuMECcoSEwClGieU/fkAVmUp8a3vCOIFRcBaSWbO QzFrAyLSKUaM4tagstUjXyFAvqSgzPaMkNzEzR9fQwFQvN7W4ODE9NScxqVgvOT93EyMwROsZ GBh3MN6d7HeIUZKDSUmU90L/43AhvqT8lMqMxOKM+KLSnNTiQ4wyHBxKEryPLwHlBItS01Mr0 jJzgNECk5bg4FES4S2+DJTmLS5IzC3OTIdInWJUlBLn/Q3SJwCSyCjNg2uDReglRlkpYV5GBg YGIZ6C1KLczBJU+VeM4hyMSsK8YiDjeTLzSuCmvwJazAS0eMvPByCLSxIRUlINjKubH1kpmc/ 4WhR8p2LLFserm+XPr3Sc7vFpg7ZR0Npt9deKRd7Mr1nYpiLQaHihl8n9bZXXxKdJCW8itesP Ttqs7jxl3wTz/Ts4Y8p5yhXd1co3LdA5cHn95ZyrZXKfqy/nTNaNO98XzvpabC0Hm9y5rXoPN vI/u9sf391Q8kzlkNemlwfeySmxFGckGmoxFxUnAgBlBygfywIAAA== X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-3.tower-206.messagelabs.com!1474548799!57308849!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 21402 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-3.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 22 Sep 2016 12:53:22 -0000 Received: from 172.24.1.137 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CIG48130; Thu, 22 Sep 2016 20:53:04 +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:56 +0800 From: z00226004 To: Date: Thu, 22 Sep 2016 20:52:26 +0800 Message-ID: <1474548753-12596-10-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.0A020204.57E3D431.009C, 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: 62a64b3146bb44e7cb96caf5b2161230 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 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: , 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 Acked-by: Julien Grall --- 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 2488c0f..8716a81 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, int nr_cpus, + xc_domain_configuration_t *xc_config, + 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 (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 += ACPI_MADT_GICC_SIZE_v5 * 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 += ACPI_MADT_GICC_SIZE_v5 * 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"); + 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, libxl__domain_build_state *state, struct xc_dom_image *dom) @@ -258,6 +341,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->max_vcpus, xc_config, acpitables); out: return rc;