From patchwork Tue Nov 17 09:40:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 7634911 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 25DB29F2EC for ; Tue, 17 Nov 2015 10:02:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E6A920499 for ; Tue, 17 Nov 2015 10:02:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A699620494 for ; Tue, 17 Nov 2015 10:02:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zyd3J-0007qN-JC; Tue, 17 Nov 2015 09:59:53 +0000 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zycrb-0002bZ-Al for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2015 09:47:49 +0000 Received: by wmec201 with SMTP id c201so17317968wme.1 for ; Tue, 17 Nov 2015 01:47:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ti27rU726zIfFdtiXAB/QNGt2Akz8/1glUdL8ak/7y4=; b=wGl/OOTaY8W2o6vB19q8h0Rf8+66B5OLcvIWvaNBN/RoCsRDQBf6Pkqa8vAlseRZdK GQ9YnV5YnzQlB/NGc3dDxc/69qYQ++CMT3y4MdX8jA6UsCk9RLee2uibB6FcbdVOF7tD KHo79d3j/mHeYxyYzNhDDoVKLl4CJHuNNgMjS4WGDGsP6WM7hfIIU5evlPyNJT22BugJ dtMVpOyM6UZLNVcNJJqyDhfj2ZULceDEvWwYLHmrodzX5ZTFdtlYCGFDT3Fj3f6Ri2sP vUgHU7KAcIZKNxTwYjc3QLPWAzBdMooDOC9WxmQD/wOit37SMcxTh3gtxk2z+jpFZBN2 GHjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ti27rU726zIfFdtiXAB/QNGt2Akz8/1glUdL8ak/7y4=; b=m3IYs007/VgpuD6OONAts+HcY5EKFlJL2TQvac9uiCz7oO2hlDBUv+LkxggUf/hggS bWCulHT0hIOQXdUuypCTX1LcDRDqUe0R+MopIoQC61qcxKHsj8gCpxl4Bj+LpjFc6F+o AVi2QhFhNZJHd6ndcy8n2gfOB1wcwMgp3iMOfV23iCfAW/edCp6HcDPTyCzMLRz+3WXt fDGBEzcvxMSvsjqwXbR9LHwtqGmSqIMn9pAZ/Fy26Xo9vYDW9gxQsFKnHabdqsbs3Jld GIFoL9K9G13ZteDypZRwZypKM5nFwQIaebkFRY7chY6MUrI6AuouT7WgyeLr2Z19yBmM MNag== X-Gm-Message-State: ALoCoQkeWZnNqZ2Da1RNmtiVwHbzyyxa6gDMf9thv/QSML+TI9zFPS+OM0cLrSbS8xRo7IBwl/qB X-Received: by 10.194.8.9 with SMTP id n9mr42956074wja.22.1447753645474; Tue, 17 Nov 2015 01:47:25 -0800 (PST) Received: from localhost ([78.129.251.54]) by smtp.gmail.com with ESMTPSA id q6sm18452790wmd.8.2015.11.17.01.47.22 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 17 Nov 2015 01:47:24 -0800 (PST) From: shannon.zhao@linaro.org To: ian.campbell@citrix.com, stefano.stabellini@citrix.com, keir@xen.org, jbeulich@suse.com, andrew.cooper3@citrix.com, julien.grall@citrix.com, xen-devel@lists.xen.org Subject: [PATCH v3 43/62] arm/acpi: Prepare MADT table for Dom0 Date: Tue, 17 Nov 2015 17:40:42 +0800 Message-Id: <1447753261-7552-44-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1447753261-7552-1-git-send-email-shannon.zhao@linaro.org> References: <1447753261-7552-1-git-send-email-shannon.zhao@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151117_014747_795246_41C46535 X-CRM114-Status: GOOD ( 12.50 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, hangaohuai@huawei.com, ard.biesheuvel@linaro.org, shannon.zhao@linaro.org, christoffer.dall@linaro.org, peter.huangpeng@huawei.com, david.vrabel@citrix.com, zhaoshenglong@huawei.com, linux-arm-kernel@lists.infradead.org, roger.pau@citrix.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shannon Zhao Copy and modify MADT table before passing it to Dom0. Copy dom0_max_vcpus of GICCs and GICD as well. Signed-off-by: Shannon Zhao --- xen/arch/arm/domain_build.c | 98 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 5d03dc0..4591955 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1359,6 +1359,100 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo) #ifdef CONFIG_ACPI #define XEN_HYPERVISOR_ID 0x000058656E564D4D /* "XenVMM" */ +static int acpi_create_madt(struct domain *d, struct membank tbl_add[]) +{ + struct acpi_table_header *table = NULL; + struct acpi_table_madt *madt = NULL; + struct acpi_madt_generic_distributor gicd; + u64 table_size = sizeof(struct acpi_table_madt); + acpi_status status; + int i; + u8 *base_ptr; + u8 checksum; + + status = acpi_get_table(ACPI_SIG_MADT, 0, &table); + + if ( ACPI_FAILURE(status) ) + { + const char *msg = acpi_format_exception(status); + + printk("Failed to get MADT table, %s\n", msg); + return -EINVAL; + } + + base_ptr = d->arch.efi_acpi_table + + acpi_get_table_offset(tbl_add, TBL_MADT); + ACPI_MEMCPY(base_ptr, table, table_size); + + /* Add Generic Distributor */ + memset(&gicd, 0, sizeof(gicd)); + gicd.header.type = ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR; + gicd.header.length = sizeof(gicd); + gicd.base_address = d->arch.vgic.dbase; + if ( d->arch.vgic.version == GIC_V2 ) + gicd.version = ACPI_MADT_GIC_VERSION_V2; + else if ( d->arch.vgic.version == GIC_V3 ) + gicd.version = ACPI_MADT_GIC_VERSION_V3; + else + gicd.version = ACPI_MADT_GIC_VERSION_NONE; + ACPI_MEMCPY(base_ptr + table_size, &gicd, sizeof(gicd)); + table_size += sizeof(gicd); + + if ( d->arch.vgic.version == GIC_V3 ) { + /* Add Generic Redistributor */ + for ( i = 0; i < d->arch.vgic.nr_regions; i++ ) { + struct acpi_madt_generic_redistributor gicr; + + memset(&gicr, 0, sizeof(gicr)); + gicr.header.type = ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR; + gicr.header.length = sizeof(gicr); + gicr.base_address = d->arch.vgic.rdist_regions[i].base; + gicr.length = d->arch.vgic.rdist_regions[i].size; + ACPI_MEMCPY(base_ptr + table_size, &gicr, sizeof(gicr)); + table_size += sizeof(gicr); + } + } else { + /* Add Generic Interrupt */ + for ( i = 0; i < d->max_vcpus; i++ ) + { + struct acpi_madt_generic_interrupt gicc; + u64 mpidr = 0; + u32 id = i, j = 0; + + memset(&gicc, 0, sizeof(gicc)); + gicc.header.type = ACPI_MADT_TYPE_GENERIC_INTERRUPT; + gicc.header.length = sizeof(gicc); + gicc.cpu_interface_number = i; + gicc.uid = i; + gicc.flags = ACPI_MADT_ENABLED; + gicc.base_address = d->arch.vgic.cbase; + + do { + mpidr |= (id % 4) << (8 * j); + j++; + if ( j ==3 ) + j++; + id = id / 4; + } while(id > 0); + gicc.arm_mpidr = mpidr; + + ACPI_MEMCPY(base_ptr + table_size, &gicc, sizeof(gicc)); + table_size += sizeof(gicc); + } + } + + madt = (struct acpi_table_madt *)base_ptr; + madt->header.length = table_size; + checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, madt), table_size); + madt->header.checksum -= checksum; + + tbl_add[TBL_MADT].start = d->arch.efi_acpi_gpa + + acpi_get_table_offset(tbl_add, TBL_MADT); + tbl_add[TBL_MADT].size = table_size; + + return 0; +} + static int acpi_create_fadt(struct domain *d, struct membank tbl_add[]) { struct acpi_table_header *table = NULL; @@ -1463,6 +1557,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo) if ( rc != 0 ) return rc; + rc = acpi_create_madt(d, tbl_add); + if ( rc != 0 ) + return rc; + return 0; } #else