From patchwork Tue Aug 16 10:25:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 74001 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1919662qga; Tue, 16 Aug 2016 03:32:17 -0700 (PDT) X-Received: by 10.36.249.8 with SMTP id l8mr20577732ith.13.1471343532246; Tue, 16 Aug 2016 03:32:12 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id q1si21292396itb.93.2016.08.16.03.32.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Aug 2016 03:32: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 1bZbd4-0002YU-J2; Tue, 16 Aug 2016 10:29:54 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZbd3-0002XF-1Y for xen-devel@lists.xen.org; Tue, 16 Aug 2016 10:29:53 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id DA/6B-28813-02BE2B75; Tue, 16 Aug 2016 10:29:52 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRWlGSWpSXmKPExsVSPpHPSVf+9aZ wg2Wf9CyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ox1/ctYCnbIV2w7doqlgXGmRBcjJ4eQwClG iTXrzLsYuYDsPYwSnVs7mUESbAK6Eh83TmEHsUUEZCVWd81hByliFrjOKHHn/TZWkISwgJ3Eu wfv2EBsFgFViTNXJwM1c3DwCnhKXGyLBwlLCGhIrOydwAIS5gQKX5vCBrHXQ+L0zIVgU3gFBC VOznzCAmIzC0hIHHzxghmiVVGibf1JNghbUuLgihssICdIgNx8aPcPqISpxI6mW4wTGAVnIZk 1C8msBYxMqxg1ilOLylKLdI1M9JKKMtMzSnITM3N0DQ2M9XJTi4sT01NzEpOK9ZLzczcxAsOz noGBcQfjq+N+hxglOZiURHlnTtwYLsSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC1/nVpnAhwaLU9 NSKtMwcYKTApCU4eJREeFVA0rzFBYm5xZnpEKlTjIpS4rw2IAkBkERGaR5cGyw6LzHKSgnzMj IwMAjxFKQW5WaWoMq/YhTnYFQS5k0GmcKTmVcCN/0V0GImoMX60htAFpckIqSkGhil9u0Q3Ve 3KHTZNJFPftW8Z+4aNvcvmPA5KvRKB8tP351b2XJKlv1/cqcoveebeEemXn+U9N4JecbPtWL1 N9bE9jfYqSkYGVx++zY4uKNqzqJre7ZsOXlHK/27SufMRWe0jvevy75cEvLYhzMw+NdX3onyZ 80E1E//O+T994HlCaFIpRLnd++VWIozEg21mIuKEwH8HkrZyQIAAA== X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1471343388!55119816!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 24277 invoked from network); 16 Aug 2016 10:29:51 -0000 Received: from szxga03-in.huawei.com (HELO szxga03-in.huawei.com) (119.145.14.66) by server-10.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 16 Aug 2016 10:29:51 -0000 Received: from 172.24.1.47 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.47]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CGJ21741; Tue, 16 Aug 2016 18:26:21 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Tue, 16 Aug 2016 18:25:38 +0800 From: Shannon Zhao To: Date: Tue, 16 Aug 2016 18:25:06 +0800 Message-ID: <1471343113-10652-10-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1471343113-10652-1-git-send-email-zhaoshenglong@huawei.com> References: <1471343113-10652-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.0A020202.57B2EA4E.0004, 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: d50be899acdabc42728c71b39516c6db 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 v4 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 --- 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 28fb6fe..75dfcc2 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -203,6 +203,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) +{ + 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; + 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 += 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"); + 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) @@ -234,6 +317,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;