From patchwork Thu Jun 23 03:16:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 70711 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp217257qgy; Wed, 22 Jun 2016 20:20:30 -0700 (PDT) X-Received: by 10.36.47.76 with SMTP id j73mr18795512itj.82.1466652024748; Wed, 22 Jun 2016 20:20:24 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id g100si5320800iod.75.2016.06.22.20.20.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jun 2016 20:20:24 -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 1bFv9a-0000AK-Bg; Thu, 23 Jun 2016 03:18:06 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFv9Z-00009P-6d for xen-devel@lists.xen.org; Thu, 23 Jun 2016 03:18:05 +0000 Received: from [193.109.254.147] by server-8.bemta-14.messagelabs.com id 2F/04-02130-CE45B675; Thu, 23 Jun 2016 03:18:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBIsWRWlGSWpSXmKPExsVSPpHPSfdlSHa 4wZ2FohZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a0G9tZC3arVFx+1s/YwPhduouRi0NI4BSj xKn22+wQzh5GiZ/He9m6GDk52AR0JT5unMIOYosIyEqs7poDVsQscJ1R4s77bawgCWEBO4neH V1gDSwCqhLPdz5nAbF5BTwk3t86BNYsIaAhsbJ3AlicEyh+ctYTZhBbSMBdYs6avVD1ghInZz 4Bs5kFJCQOvnjBDNGrKNG2/iQbhC0pcXDFDRaQIyRAzp595zLUAlOJ9b/WMk1gFJyFZNYsJLM WMDKtYlQvTi0qSy3SNdNLKspMzyjJTczM0TU0NNHLTS0uTkxPzUlMKtZLzs/dxAgMUQYg2MH4 d4LzIUZJDiYlUV4rh+xwIb6k/JTKjMTijPii0pzU4kOMMhwcShK8jsFAOcGi1PTUirTMHGC0w KQlOHiURHglQNK8xQWJucWZ6RCpU4yKUuK89iAJAZBERmkeXBssQi8xykoJ8zICHSLEU5BalJ tZgir/ilGcg1FJmDcNZApPZl4J3PRXQIuZgBYv608HWVySiJCSamAsrBdxiFh0c6KRaTnTuo3 m/ppfH3y/+bA1TUfdZPK1E78Wr2Ermzp5n3rQjn/hzClBTXfPXp+mp7sucf92q8UywvIxKzkf /n/RcyPl0dv7x751KjxRCj+eFDEv7lt2VWeq8KlEzobyaAtPRqmfr2S9+43T1+zemVngGXCx2 PeK0ueA71wLDh1UYinOSDTUYi4qTgQA7yrH7csCAAA= X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1466651878!49071496!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.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32668 invoked from network); 23 Jun 2016 03:17:59 -0000 Received: from szxga03-in.huawei.com (HELO szxga03-in.huawei.com) (119.145.14.66) by server-3.tower-27.messagelabs.com with SMTP; 23 Jun 2016 03:17:59 -0000 Received: from 172.24.1.36 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.36]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CDT13166; Thu, 23 Jun 2016 11:17:38 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Thu, 23 Jun 2016 11:17:31 +0800 From: Shannon Zhao To: Date: Thu, 23 Jun 2016 11:16:56 +0800 Message-ID: <1466651824-6964-10-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1466651824-6964-1-git-send-email-zhaoshenglong@huawei.com> References: <1466651824-6964-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.0A090204.576B54D3.003C, 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: aef68bd94a3e40a00ee32807714911cc 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 v2 09/17] 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 | 100 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c index de863f4..659dbfa 100644 --- a/tools/libxl/libxl_arm_acpi.c +++ b/tools/libxl/libxl_arm_acpi.c @@ -42,6 +42,8 @@ typedef uint64_t u64; #define ACPI_LEVEL_SENSITIVE (u8) 0x00 #define ACPI_ACTIVE_LOW (u8) 0x01 +#define ACPI_GICC_ENABLED 1 + enum { RSDP, XSDT, @@ -137,6 +139,101 @@ static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom) dom->acpitable_size += ROUNDUP(acpitables[GTDT].size, 3); } +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_GICC_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 filed 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) +{ + size_t size; + void *table; + struct acpi_table_madt *madt; + + switch (xc_config->gic_version) { + case XEN_DOMCTL_CONFIG_GIC_V2: + size = sizeof(struct acpi_table_madt) + + sizeof(struct acpi_madt_generic_interrupt) * nr_cpus + + sizeof(struct acpi_madt_generic_distributor); + table = libxl__zalloc(gc, size); + madt = (struct acpi_table_madt *)table; + + 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: + size = sizeof(struct acpi_table_madt) + + 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_table_madt *)table; + + 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"); + return ERROR_FAIL; + } + + make_acpi_header(&madt->header, "APIC", size, 3); + + acpitables[MADT].table = madt; + acpitables[MADT].size = size; + /* Align to 64bit. */ + dom->acpitable_size += ROUNDUP(acpitables[MADT].size, 3); + + return 0; +} + int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, libxl__domain_build_state *state, struct xc_dom_image *dom) @@ -160,6 +257,9 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info, make_acpi_rsdp(gc, dom); make_acpi_xsdt(gc, dom); make_acpi_gtdt(gc, dom); + rc = make_acpi_madt(gc, dom, info->max_vcpus, xc_config); + if (rc) + return rc; return 0; }