From patchwork Tue May 31 05:03:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 68878 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1732501qge; Mon, 30 May 2016 22:05:14 -0700 (PDT) X-Received: by 10.31.202.71 with SMTP id a68mr15865008vkg.79.1464671112154; Mon, 30 May 2016 22:05:12 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id f126si22913215vke.22.2016.05.30.22.05.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 22:05: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 1b7bqX-0003Kl-Qr; Tue, 31 May 2016 05:04:05 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b7bqW-0003Hb-AL for xen-devel@lists.xen.org; Tue, 31 May 2016 05:04:04 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id C8/E6-02690-34B1D475; Tue, 31 May 2016 05:04:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVSPpHPSddZ2jf coNHCYsnHxSwOjB5Hd/9mCmCMYs3MS8qvSGDNONKygbVgrWrFwymrGBsYt8t0MXJxCAmcYpQ4 f2w5cxcjJ5Czh1Hi/WdhEJtNQFfi48Yp7CC2iICsxOquOewgDcwCGxklnrz9ygaSEBZwkpjTe pAVxGYRUJVoXj8JLM4r4CGxaMtDJhBbQkBDYmXvBBYQm1PAU+LIx+csEMs8JFobdzBC1AtKnJ z5BCzOLCAhcfDFC2aIXkWJtvUn2SBsSYmDK26wgBwhAXL14rV/WSESphKLl71hn8AoOAvJrFl IZi1gZFrFqFGcWlSWWqRraKKXVJSZnlGSm5iZo2toYKyXm1pcnJiempOYVKyXnJ+7iREYoAxA sINxxXbPQ4ySHExKorxWv33ChfiS8lMqMxKLM+KLSnNSiw8xynBwKEnw6kr5hgsJFqWmp1akZ eYAYwUmLcHBoyTCawSS5i0uSMwtzkyHSJ1iVJQS540HSQiAJDJK8+DaYPF5iVFWSpiXEegQIZ 6C1KLczBJU+VeM4hyMSsK8HCBTeDLzSuCmvwJazAS0OD7DB2RxSSJCSqqBsWuuwj2F7Ir9wTY LBcw2VoU//nXlyzMtTm/PfdtTI47fM1jU9NV+kRUDq9Bn+0SeaCMZ5neWR1ltZeJUDy2ac9lR hIvBxnBnlLLTKo5X3g8yLjwWuS5ZmrCiIth4xXnbztAd21ZWcbyaq8Gs693ky/Tlw/0fx2fWT KgoUurQbPdkyrML4XZXYinOSDTUYi4qTgQAxgXXJ8oCAAA= X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1464671037!42281724!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.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3482 invoked from network); 31 May 2016 05:04:02 -0000 Received: from szxga03-in.huawei.com (HELO szxga03-in.huawei.com) (119.145.14.66) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 31 May 2016 05:04:02 -0000 Received: from 172.24.1.60 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.60]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CCK68371; Tue, 31 May 2016 13:03:41 +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, 31 May 2016 13:03:30 +0800 From: Shannon Zhao To: Date: Tue, 31 May 2016 13:03:00 +0800 Message-ID: <1464670986-10256-9-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1464670986-10256-1-git-send-email-zhaoshenglong@huawei.com> References: <1464670986-10256-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.574D1B2F.002A, 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: 211128c7d5f3919b728ad6e3ca138d08 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 Subject: [Xen-devel] [PATCH RESEND 08/14] 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.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c index 7949635..f72f692 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -958,11 +958,115 @@ static void make_acpi_dsdt(libxl__gc *gc, struct xc_dom_image *dom) dom->acpitable_size += ROUNDUP(dom->acpitable_blob->dsdt.size, 3); } +static void make_acpi_madt_gicc(void *table, int nr_cpus, uint64_t gicc_base) +{ + uint32_t i; + uint64_t mpidr_aff; + struct acpi_madt_generic_interrupt *gicc = table; + + for (i = 0; i < nr_cpus; i++) { + gicc->type = ACPI_APIC_GENERIC_INTERRUPT; + gicc->length = sizeof(*gicc); + gicc->base_address = gicc_base; + gicc->cpu_interface_number = i; + + /* + * We will use AFF0 and AFF1 when constructing the MPIDR value of the + * guest at the moment, for it is enough for the current max vcpu + * number. + */ + mpidr_aff = (i & 0x0f) | (((i >> 4) & 0xff) << 8); + gicc->arm_mpidr = mpidr_aff; + gicc->uid = i; + gicc->flags = 1; + + gicc += 1; + } +} + +static void make_acpi_madt_gicd(void *table, uint64_t gicd_base, + uint8_t gic_version) +{ + struct acpi_madt_generic_distributor *gicd = table; + + gicd->type = ACPI_APIC_GENERIC_DISTRIBUTOR; + gicd->length = sizeof(*gicd); + gicd->base_address = gicd_base; + 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->type = ACPI_APIC_GENERIC_REDISTRIBUTOR; + gicr->length = sizeof(*gicr); + gicr->base_address = gicr_base; + gicr->range_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) +{ + uint32_t size; + void *table; + struct acpi_madt_descriptor *madt; + + switch (xc_config->gic_version) { + case XEN_DOMCTL_CONFIG_GIC_V2: + size = sizeof(struct acpi_madt_descriptor) + + sizeof(struct acpi_madt_generic_interrupt) * nr_cpus + + sizeof(struct acpi_madt_generic_distributor); + table = libxl__zalloc(gc, size); + madt = (struct acpi_madt_descriptor *)table; + + table += sizeof(struct acpi_madt_descriptor); + 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, 2); + break; + case XEN_DOMCTL_CONFIG_GIC_V3: + size = sizeof(struct acpi_madt_descriptor) + + sizeof(struct acpi_madt_generic_interrupt) * nr_cpus + + sizeof(struct acpi_madt_generic_distributor) + + sizeof(struct acpi_madt_generic_redistributor); + table = libxl__zalloc(gc, size); + madt = (struct acpi_madt_descriptor *)table; + + table += sizeof(struct acpi_madt_descriptor); + 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, 3); + + 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 %s", + gicv_to_string(xc_config->gic_version)); + return ERROR_FAIL; + } + + make_acpi_header(&madt->header, "APIC", size, 3); + + dom->acpitable_blob->madt.table = (void *)madt; + /* Align to 64bit. */ + dom->acpitable_blob->madt.size = size; + dom->acpitable_size += dom->acpitable_blob->madt.size; + + return 0; +} + static int prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, libxl__domain_build_state *state, struct xc_dom_image *dom) { const libxl_version_info *vers; + int rc; /* convenience aliases */ xc_domain_configuration_t *xc_config = &state->config; @@ -981,6 +1085,9 @@ static int prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, make_acpi_gtdt(gc, dom); make_acpi_fadt(gc, dom); make_acpi_dsdt(gc, dom); + rc = make_acpi_madt(gc, dom, info->max_vcpus, xc_config); + if (rc) + return rc; return 0; }