From patchwork Tue May 31 04:43:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 68872 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1727946qge; Mon, 30 May 2016 21:51:07 -0700 (PDT) X-Received: by 10.55.47.70 with SMTP id v67mr28908166qkh.135.1464670267424; Mon, 30 May 2016 21:51:07 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id g90si20776999qgg.13.2016.05.30.21.51.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 21:51:07 -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 1b7bcp-0000EI-BU; Tue, 31 May 2016 04:49:55 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b7bco-0000Cb-4c for xen-devel@lists.xen.org; Tue, 31 May 2016 04:49:54 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id 2A/11-17405-1F71D475; Tue, 31 May 2016 04:49:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVSPpHPSfeDuG+ 4weeXFhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aRlg2sBWtVKx5OWcXYwLhdpouRi0NI4Ayj xJlpbewQzh5Gibmf97N1MXJysAnoSnzcOIUdxBYRkJVY3TUHrIhZYBOjRNuXiywgCWEBa4mfF z6ygtgsAqoSN35eAWvmFfCQ6G3eCVYjIaAhsbJ3ApjNKeApcX7iS2YQWwioZt+y04wQ9YISJ2 c+AathFpCQOPjiBTNEr6JE2/qTbBC2pMTBFTegZp5ilLizgBvCNpV4dqeffQKj4Cwko2YhGbW AkWkVo3pxalFZapGumV5SUWZ6RkluYmaOrqGBsV5uanFxYnpqTmJSsV5yfu4mRmCA1jMwMO5g vNLmfIhRkoNJSZTX6rdPuBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ3ptivuFCgkWp6akVaZk5w FiBSUtw8CiJ8CoB40WIt7ggMbc4Mx0idYpRUUqcdwFInwBIIqM0D64NFp+XGGWlhHkZGRgYhH gKUotyM0tQ5V8xinMwKgnzNoFM4cnMK4Gb/gpoMRPQ4vgMH5DFJYkIKakGxtNW8yNn3HrB+Hr O7U11FoeVLC7IW/awXJty8FGcWXdazIs7hcnPZkjbTWmfe/CKtVjKl1NzotZNONIUcL9XWodv vkribRGOP77PG9Wci4+3Xrp+zFmwdqph31uzIrHsUx/D5iw8f1SF81lDnyzbuqOmP8uzL6ftv dqXdkLv3em5a9e8NI/d/kaJpTgj0VCLuag4EQCQAFeYygIAAA== X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1464670187!33198136!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 8057 invoked from network); 31 May 2016 04:49:52 -0000 Received: from szxga03-in.huawei.com (HELO szxga03-in.huawei.com) (119.145.14.66) by server-4.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 31 May 2016 04:49:52 -0000 Received: from 172.24.1.137 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CCK66910; Tue, 31 May 2016 12:44:48 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Tue, 31 May 2016 12:44:37 +0800 From: Shannon Zhao To: Date: Tue, 31 May 2016 12:43:30 +0800 Message-ID: <1464669816-11476-9-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1464669816-11476-1-git-send-email-zhaoshenglong@huawei.com> References: <1464669816-11476-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.0A020201.574D170C.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: 9e52bc98a020d80299b5527f5e9cc8d6 Cc: sstabellini@kernel.org, ian.jackson@eu.citrix.com, peter.huangpeng@huawei.com, julien.grall@arm.com, shannon.zhao@linaro.org, wei.liu2@citrix.comg Subject: [Xen-devel] [PATCH 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; }