From patchwork Wed Aug 21 03:53:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11105341 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B304D1805 for ; Wed, 21 Aug 2019 03:54:56 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F65D22CF7 for ; Wed, 21 Aug 2019 03:54:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="QT77O75S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F65D22CF7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0HgV-0007X1-NJ; Wed, 21 Aug 2019 03:53:19 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0HgU-0007Ww-Iz for xen-devel@lists.xen.org; Wed, 21 Aug 2019 03:53:18 +0000 X-Inumbo-ID: 35ad66f4-c3c7-11e9-adbf-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 35ad66f4-c3c7-11e9-adbf-12813bfff9fa; Wed, 21 Aug 2019 03:53:18 +0000 (UTC) Received: from localhost.localdomain (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1CF6E22CF7; Wed, 21 Aug 2019 03:53:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566359597; bh=ilQvgcR3MulEE8QKmpCmddKy6h/nXy87f0rlM3P6H+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QT77O75SA/s/xPAZaCPmmjMhAVbI6poPlxWFFK0CpFaDmyLxs22ZfBujrSpsV6TyO 1tsUEzvFwd0cFYSBJj02i+kp3isa2cA+29iLjlECAKo0Q67Vffxkb9rnLE+xVpcTOO A2d4YwMM3ixqwT0LUi+CBFJo8q+S63e+DgsDYsd4= From: Stefano Stabellini To: julien.grall@arm.com Date: Tue, 20 Aug 2019 20:53:08 -0700 Message-Id: <20190821035315.12812-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 1/8] xen/arm: introduce handle_device_interrupts X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, andrii_anisov@epam.com, Achin.Gupta@arm.com, xen-devel@lists.xen.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Move the interrupt handling code out of handle_device to a new function so that it can be reused for dom0less VMs (it will be used in later patches). Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v4: - rename handle_interrupts to handle_device_interrupts - improve in-code comment - remove return 1 if mapping is done - use unsigned Changes in v3: - add patch The diff is hard to read but I just moved the interrupts related code from handle_devices to a new function handle_device_interrupts, and very little else. --- xen/arch/arm/domain_build.c | 80 +++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 29 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 4c8404155a..f92069c85f 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1220,41 +1220,22 @@ static int __init map_device_children(struct domain *d, } /* - * For a given device node: - * - Give permission to the guest to manage IRQ and MMIO range - * - Retrieve the IRQ configuration (i.e edge/level) from device tree - * When the device is not marked for guest passthrough: - * - Assign the device to the guest if it's protected by an IOMMU - * - Map the IRQs and iomem regions to DOM0 + * handle_device_interrupts retrieves the interrupts configuration from + * a device tree node and maps those interrupts to the target domain. + * + * Returns: + * < 0 error + * 0 success */ -static int __init handle_device(struct domain *d, struct dt_device_node *dev, - p2m_type_t p2mt) +static int __init handle_device_interrupts(struct domain *d, + struct dt_device_node *dev, + bool need_mapping) { - unsigned int nirq; - unsigned int naddr; - unsigned int i; + unsigned int i, nirq; int res; struct dt_raw_irq rirq; - u64 addr, size; - bool need_mapping = !dt_device_for_passthrough(dev); nirq = dt_number_of_irq(dev); - naddr = dt_number_of_address(dev); - - dt_dprintk("%s passthrough = %d nirq = %d naddr = %u\n", - dt_node_full_name(dev), need_mapping, nirq, naddr); - - if ( dt_device_is_protected(dev) && need_mapping ) - { - dt_dprintk("%s setup iommu\n", dt_node_full_name(dev)); - res = iommu_assign_dt_device(d, dev); - if ( res ) - { - printk(XENLOG_ERR "Failed to setup the IOMMU for %s\n", - dt_node_full_name(dev)); - return res; - } - } /* Give permission and map IRQs */ for ( i = 0; i < nirq; i++ ) @@ -1291,6 +1272,47 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, return res; } + return 0; +} + +/* + * For a given device node: + * - Give permission to the guest to manage IRQ and MMIO range + * - Retrieve the IRQ configuration (i.e edge/level) from device tree + * When the device is not marked for guest passthrough: + * - Assign the device to the guest if it's protected by an IOMMU + * - Map the IRQs and iomem regions to DOM0 + */ +static int __init handle_device(struct domain *d, struct dt_device_node *dev, + p2m_type_t p2mt) +{ + unsigned int naddr; + unsigned int i; + int res; + u64 addr, size; + bool need_mapping = !dt_device_for_passthrough(dev); + + naddr = dt_number_of_address(dev); + + dt_dprintk("%s passthrough = %d naddr = %u\n", + dt_node_full_name(dev), need_mapping, naddr); + + if ( dt_device_is_protected(dev) && need_mapping ) + { + dt_dprintk("%s setup iommu\n", dt_node_full_name(dev)); + res = iommu_assign_dt_device(d, dev); + if ( res ) + { + printk(XENLOG_ERR "Failed to setup the IOMMU for %s\n", + dt_node_full_name(dev)); + return res; + } + } + + res = handle_device_interrupts(d, dev, need_mapping); + if ( res < 0 ) + return res; + /* Give permission and map MMIOs */ for ( i = 0; i < naddr; i++ ) { From patchwork Wed Aug 21 03:53:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11105347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E5ED1805 for ; Wed, 21 Aug 2019 03:55:22 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3AFCE22CF7 for ; Wed, 21 Aug 2019 03:55:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="XmPmx8yw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3AFCE22CF7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0HgX-0007XJ-WB; Wed, 21 Aug 2019 03:53:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0HgW-0007X7-4G for xen-devel@lists.xen.org; Wed, 21 Aug 2019 03:53:20 +0000 X-Inumbo-ID: 36123bba-c3c7-11e9-ac23-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 36123bba-c3c7-11e9-ac23-bc764e2007e4; Wed, 21 Aug 2019 03:53:19 +0000 (UTC) Received: from localhost.localdomain (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C44552332B; Wed, 21 Aug 2019 03:53:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566359598; bh=SNGQV1FRvvnk1EbxM0rXZvy7bRJiTL03suL/GJScJ0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XmPmx8yw3Vzss0+vBBhVqr1czSpPbcwZquoS2Fm25YcMiCCHgp5Zlx0M8BnOoG4w4 bkAQkSV4NKMpJsMfn/B62cBD/n6iwSSxY+K5W2V/IldPPHJNwY/yNFPFznjN1N14zD 1BCXr8sxZnl7DJDO4GkHf7pmPxuIZ+6a+ZoKHeCM= From: Stefano Stabellini To: julien.grall@arm.com Date: Tue, 20 Aug 2019 20:53:09 -0700 Message-Id: <20190821035315.12812-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 2/8] xen/arm: export device_tree_get_reg and device_tree_get_u32 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, andrii_anisov@epam.com, Achin.Gupta@arm.com, xen-devel@lists.xen.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" They'll be used in later patches. Signed-off-by: Stefano Stabellini --- Changes in v4: - new patch --- xen/arch/arm/bootfdt.c | 8 ++++---- xen/include/xen/device_tree.h | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 891b4b66ff..4b7898be13 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -55,15 +55,15 @@ static bool __init device_tree_node_compatible(const void *fdt, int node, return false; } -static void __init device_tree_get_reg(const __be32 **cell, u32 address_cells, - u32 size_cells, u64 *start, u64 *size) +void __init device_tree_get_reg(const __be32 **cell, u32 address_cells, + u32 size_cells, u64 *start, u64 *size) { *start = dt_next_cell(address_cells, cell); *size = dt_next_cell(size_cells, cell); } -static u32 __init device_tree_get_u32(const void *fdt, int node, - const char *prop_name, u32 dflt) +u32 __init device_tree_get_u32(const void *fdt, int node, + const char *prop_name, u32 dflt) { const struct fdt_property *prop; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 83156297e2..4510d9b580 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -162,6 +162,12 @@ int device_tree_for_each_node(const void *fdt, device_tree_node_func func, void *data); +void device_tree_get_reg(const __be32 **cell, u32 address_cells, + u32 size_cells, u64 *start, u64 *size); + +u32 device_tree_get_u32(const void *fdt, int node, + const char *prop_name, u32 dflt); + /** * dt_unflatten_host_device_tree - Unflatten the host device tree * From patchwork Wed Aug 21 03:53:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11105351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70C8214F7 for ; Wed, 21 Aug 2019 03:55:27 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4DA8222CF7 for ; Wed, 21 Aug 2019 03:55:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="fxzJxZ5x" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4DA8222CF7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hgc-0007Xs-IC; Wed, 21 Aug 2019 03:53:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hgb-0007Xk-1o for xen-devel@lists.xen.org; Wed, 21 Aug 2019 03:53:25 +0000 X-Inumbo-ID: 367f4eb2-c3c7-11e9-b95f-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 367f4eb2-c3c7-11e9-b95f-bc764e2007e4; Wed, 21 Aug 2019 03:53:19 +0000 (UTC) Received: from localhost.localdomain (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6EF5E2339D; Wed, 21 Aug 2019 03:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566359598; bh=0JAGiiQQ732nc8ZspiQCbWNnIAh8yRVZZlfqy6Ku0ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fxzJxZ5xNNv88PsfeBElo814cCkXryTOXdJzEWR3oONAJCg/VzNW6alHUmtH6b6Pq pELtq52+y/Di37RXg2KdWshN11lXGm5Pjrmt7HJxLQL9VE7DnNwp8ymK3pCjyMS1gI 729SqGeefvGIjUyOOSn7Y2+yqYR1V4T1J4rGK4E4= From: Stefano Stabellini To: julien.grall@arm.com Date: Tue, 20 Aug 2019 20:53:10 -0700 Message-Id: <20190821035315.12812-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 3/8] xen/arm: introduce kinfo->guest_phandle_gic X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, andrii_anisov@epam.com, Achin.Gupta@arm.com, xen-devel@lists.xen.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Instead of always hard-coding the GIC phandle (GUEST_PHANDLE_GIC), store it in a variable under kinfo. This way it can be dynamically chosen per domain. Initialize guest_phandle_gic to GUEST_PHANDLE_GIC at the beginning of prepare_dtb_domU. Later patches will change the value of guest_phandle_gic depending on user provided information. Signed-off-by: Stefano Stabellini --- Changes in v4: - new patch --- xen/arch/arm/domain_build.c | 42 ++++++++++++++++++++---------------- xen/include/asm-arm/kernel.h | 3 +++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index f92069c85f..cd585f05ca 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1510,8 +1510,9 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo, return res; } -static int __init make_gicv2_domU_node(const struct domain *d, void *fdt) +static int __init make_gicv2_domU_node(struct kernel_info *kinfo) { + void *fdt = kinfo->fdt; int res = 0; __be32 reg[(GUEST_ROOT_ADDRESS_CELLS + GUEST_ROOT_SIZE_CELLS) * 2]; __be32 *cells; @@ -1546,11 +1547,11 @@ static int __init make_gicv2_domU_node(const struct domain *d, void *fdt) if (res) return res; - res = fdt_property_cell(fdt, "linux,phandle", GUEST_PHANDLE_GIC); + res = fdt_property_cell(fdt, "linux,phandle", kinfo->guest_phandle_gic); if (res) return res; - res = fdt_property_cell(fdt, "phandle", GUEST_PHANDLE_GIC); + res = fdt_property_cell(fdt, "phandle", kinfo->guest_phandle_gic); if (res) return res; @@ -1559,8 +1560,9 @@ static int __init make_gicv2_domU_node(const struct domain *d, void *fdt) return res; } -static int __init make_gicv3_domU_node(const struct domain *d, void *fdt) +static int __init make_gicv3_domU_node(struct kernel_info *kinfo) { + void *fdt = kinfo->fdt; int res = 0; __be32 reg[(GUEST_ROOT_ADDRESS_CELLS + GUEST_ROOT_SIZE_CELLS) * 2]; __be32 *cells; @@ -1595,11 +1597,11 @@ static int __init make_gicv3_domU_node(const struct domain *d, void *fdt) if (res) return res; - res = fdt_property_cell(fdt, "linux,phandle", GUEST_PHANDLE_GIC); + res = fdt_property_cell(fdt, "linux,phandle", kinfo->guest_phandle_gic); if (res) return res; - res = fdt_property_cell(fdt, "phandle", GUEST_PHANDLE_GIC); + res = fdt_property_cell(fdt, "phandle", kinfo->guest_phandle_gic); if (res) return res; @@ -1608,21 +1610,22 @@ static int __init make_gicv3_domU_node(const struct domain *d, void *fdt) return res; } -static int __init make_gic_domU_node(const struct domain *d, void *fdt) +static int __init make_gic_domU_node(struct kernel_info *kinfo) { - switch ( d->arch.vgic.version ) + switch ( kinfo->d->arch.vgic.version ) { case GIC_V3: - return make_gicv3_domU_node(d, fdt); + return make_gicv3_domU_node(kinfo); case GIC_V2: - return make_gicv2_domU_node(d, fdt); + return make_gicv2_domU_node(kinfo); default: panic("Unsupported GIC version\n"); } } -static int __init make_timer_domU_node(const struct domain *d, void *fdt) +static int __init make_timer_domU_node(struct kernel_info *kinfo) { + void *fdt = kinfo->fdt; int res; gic_interrupt_t intrs[3]; @@ -1630,7 +1633,7 @@ static int __init make_timer_domU_node(const struct domain *d, void *fdt) if ( res ) return res; - if ( !is_64bit_domain(d) ) + if ( !is_64bit_domain(kinfo->d) ) { res = fdt_property_string(fdt, "compatible", "arm,armv7-timer"); if ( res ) @@ -1652,7 +1655,7 @@ static int __init make_timer_domU_node(const struct domain *d, void *fdt) return res; res = fdt_property_cell(fdt, "interrupt-parent", - GUEST_PHANDLE_GIC); + kinfo->guest_phandle_gic); if (res) return res; @@ -1662,8 +1665,9 @@ static int __init make_timer_domU_node(const struct domain *d, void *fdt) } #ifdef CONFIG_SBSA_VUART_CONSOLE -static int __init make_vpl011_uart_node(const struct domain *d, void *fdt) +static int __init make_vpl011_uart_node(struct kernel_info *kinfo) { + void *fdt = kinfo->fdt; int res; gic_interrupt_t intr; __be32 reg[GUEST_ROOT_ADDRESS_CELLS + GUEST_ROOT_SIZE_CELLS]; @@ -1694,7 +1698,7 @@ static int __init make_vpl011_uart_node(const struct domain *d, void *fdt) return res; res = fdt_property_cell(fdt, "interrupt-parent", - GUEST_PHANDLE_GIC); + kinfo->guest_phandle_gic); if ( res ) return res; @@ -1719,6 +1723,8 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) int addrcells, sizecells; int ret; + kinfo->guest_phandle_gic = GUEST_PHANDLE_GIC; + addrcells = GUEST_ROOT_ADDRESS_CELLS; sizecells = GUEST_ROOT_SIZE_CELLS; @@ -1762,11 +1768,11 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) if ( ret ) goto err; - ret = make_gic_domU_node(d, kinfo->fdt); + ret = make_gic_domU_node(kinfo); if ( ret ) goto err; - ret = make_timer_domU_node(d, kinfo->fdt); + ret = make_timer_domU_node(kinfo); if ( ret ) goto err; @@ -1774,7 +1780,7 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) { ret = -EINVAL; #ifdef CONFIG_SBSA_VUART_CONSOLE - ret = make_vpl011_uart_node(d, kinfo->fdt); + ret = make_vpl011_uart_node(kinfo); #endif if ( ret ) goto err; diff --git a/xen/include/asm-arm/kernel.h b/xen/include/asm-arm/kernel.h index 33f3e72b11..760434369b 100644 --- a/xen/include/asm-arm/kernel.h +++ b/xen/include/asm-arm/kernel.h @@ -36,6 +36,9 @@ struct kernel_info { /* Enable pl011 emulation */ bool vpl011; + /* GIC phandle */ + uint32_t guest_phandle_gic; + /* loader to use for this kernel */ void (*load)(struct kernel_info *info); /* loader specific state */ From patchwork Wed Aug 21 03:53:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11105343 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 938261805 for ; Wed, 21 Aug 2019 03:54:58 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7025922CF7 for ; Wed, 21 Aug 2019 03:54:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="2oPPUZie" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7025922CF7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hgi-0007ar-0Y; Wed, 21 Aug 2019 03:53:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hgg-0007a2-2U for xen-devel@lists.xen.org; Wed, 21 Aug 2019 03:53:30 +0000 X-Inumbo-ID: 36e35fd8-c3c7-11e9-8980-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 36e35fd8-c3c7-11e9-8980-bc764e2007e4; Wed, 21 Aug 2019 03:53:20 +0000 (UTC) Received: from localhost.localdomain (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 22B7E2339E; Wed, 21 Aug 2019 03:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566359599; bh=s9Frwg46jacUxpsDb3kqwBKhlP+4wDLXJFA0JPCWIA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2oPPUZieQ/nNxVh+8fug0KOJ0LY9YYWvF3jSfB3JAia42SoITGRVVNzjGhX9h4joH N0z1uEBOO3mlrA9JLMnbbKfOFwKNczwEhU0YRtbKcNsdiVkebgnwPBpIdnNH4Yy5Qz JUgDvnkC3KNQldZiW84fKyt7epvBWhH9ywcDS0WE= From: Stefano Stabellini To: julien.grall@arm.com Date: Tue, 20 Aug 2019 20:53:11 -0700 Message-Id: <20190821035315.12812-4-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 4/8] xen/arm: copy dtb fragment to guest dtb X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, andrii_anisov@epam.com, Achin.Gupta@arm.com, xen-devel@lists.xen.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Read the dtb fragment corresponding to a passthrough device from memory at the location referred to by the "multiboot,device-tree" compatible node. Add a new field named dtb_bootmodule to struct kernel_info to keep track of the dtb fragment location. Copy the fragment to the guest dtb (only /aliases and /passthrough). Set kinfo->guest_phandle_gic based on the phandle of the special "/gic" node in the device tree fragment. "/gic" is a dummy node in the dtb fragment that represents the gic interrupt controller. Other properties in the dtb fragment might refer to it (for instance interrupt-parent of a device node). We reuse the phandle of "/gic" from the dtb fragment as the phandle of the full GIC node that will be created for the guest device tree. That way, when we copy properties from the device tree fragment to the domU device tree the links remain unbroken. Some of the code below is taken from tools/libxl/libxl_arm.c. Note that it is OK to take LGPL 2.1 code and including it into a GPLv2 code base. The result is GPLv2 code. Signed-off-by: Stefano Stabellini ---- Changes in v4: - use recursion in the implementation - rename handle_properties to handle_prop_pfdt - rename scan_pt_node to scan_pfdt_node - pass kinfo to handle_properties - use uint32_t instead of u32 - rename r to res - add "passthrough" and "aliases" check - add a name == NULL check - code style - move DTB fragment scanning earlier, before DomU GIC node creation - set guest_phandle_gic based on "/gic" - in-code comment Changes in v3: - switch to using device_tree_for_each_node for the copy Changes in v2: - add a note about the code coming from libxl in the commit message - copy /aliases - code style --- xen/arch/arm/domain_build.c | 112 +++++++++++++++++++++++++++++++++++ xen/include/asm-arm/kernel.h | 2 +- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index cd585f05ca..c71b9f2889 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1713,6 +1714,111 @@ static int __init make_vpl011_uart_node(struct kernel_info *kinfo) } #endif +static int __init handle_prop_pfdt(struct kernel_info *kinfo, + const void *pfdt, int nodeoff, + uint32_t address_cells, uint32_t size_cells) +{ + void *fdt = kinfo->fdt; + int propoff, nameoff, res; + const struct fdt_property *prop; + + for ( propoff = fdt_first_property_offset(pfdt, nodeoff); + propoff >= 0; + propoff = fdt_next_property_offset(pfdt, propoff) ) + { + if ( !(prop = fdt_get_property_by_offset(pfdt, propoff, NULL)) ) + return -FDT_ERR_INTERNAL; + + nameoff = fdt32_to_cpu(prop->nameoff); + res = fdt_property(fdt, fdt_string(pfdt, nameoff), + prop->data, fdt32_to_cpu(prop->len)); + if ( res ) + return res; + } + + /* FDT_ERR_NOTFOUND => There is no more properties for this node */ + return ( propoff != -FDT_ERR_NOTFOUND ) ? propoff : 0; +} + +static int __init scan_pfdt_node(struct kernel_info *kinfo, const void *pfdt, + int nodeoff, int depth, + uint32_t address_cells, uint32_t size_cells) +{ + int rc = 0; + void *fdt = kinfo->fdt; + int node_next; + const char *name = fdt_get_name(pfdt, nodeoff, NULL); + + /* + * Take the GIC phandle value from the special /gic node in the DTB + * fragment. + */ + if ( depth == 1 && dt_node_cmp(name, "gic") == 0 ) + { + kinfo->guest_phandle_gic = fdt_get_phandle(pfdt, nodeoff); + return 0; + } + + rc = fdt_begin_node(fdt, fdt_get_name(pfdt, nodeoff, NULL)); + if ( rc ) + return rc; + + rc = handle_prop_pfdt(kinfo, pfdt, nodeoff, address_cells, size_cells); + if ( rc ) + return rc; + + address_cells = device_tree_get_u32(pfdt, nodeoff, "#address-cells", + address_cells); + size_cells = device_tree_get_u32(pfdt, nodeoff, "#size-cells", + size_cells); + + node_next = fdt_first_subnode(pfdt, nodeoff); + while ( node_next > 0 ) + { + scan_pfdt_node(kinfo, pfdt, node_next, depth + 1, address_cells, size_cells); + node_next = fdt_next_subnode(pfdt, node_next); + } + + return fdt_end_node(fdt); +} + +static int __init domain_handle_dtb_bootmodule(struct domain *d, + struct kernel_info *kinfo) +{ + void *pfdt; + int res, node_next; + + pfdt = ioremap_cache(kinfo->dtb_bootmodule->start, + kinfo->dtb_bootmodule->size); + if ( pfdt == NULL ) + return -EFAULT; + + node_next = fdt_first_subnode(pfdt, 0); + while ( node_next > 0 ) + { + const char *name = fdt_get_name(pfdt, node_next, NULL); + + /* only scan /gic /aliases /passthrough, ignore the rest */ + if ( name != NULL && + (dt_node_cmp(name, "passthrough") == 0 || + dt_node_cmp(name, "aliases") == 0 || + dt_node_cmp(name, "gic") == 0) ) + { + res = scan_pfdt_node(kinfo, pfdt, node_next, 1, + DT_ROOT_NODE_ADDR_CELLS_DEFAULT, + DT_ROOT_NODE_SIZE_CELLS_DEFAULT); + if ( res ) + return res; + } + + node_next = fdt_next_subnode(pfdt, node_next); + } + + iounmap(pfdt); + + return res; +} + /* * The max size for DT is 2MB. However, the generated DT is small, 4KB * are enough for now, but we might have to increase it in the future. @@ -1768,6 +1874,12 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) if ( ret ) goto err; + if ( kinfo->dtb_bootmodule ) { + ret = domain_handle_dtb_bootmodule(d, kinfo); + if ( ret ) + return ret; + } + ret = make_gic_domU_node(kinfo); if ( ret ) goto err; diff --git a/xen/include/asm-arm/kernel.h b/xen/include/asm-arm/kernel.h index 760434369b..7f5e659561 100644 --- a/xen/include/asm-arm/kernel.h +++ b/xen/include/asm-arm/kernel.h @@ -28,7 +28,7 @@ struct kernel_info { paddr_t gnttab_size; /* boot blob load addresses */ - const struct bootmodule *kernel_bootmodule, *initrd_bootmodule; + const struct bootmodule *kernel_bootmodule, *initrd_bootmodule, *dtb_bootmodule; const char* cmdline; paddr_t dtb_paddr; paddr_t initrd_paddr; From patchwork Wed Aug 21 03:53:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11105349 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8087F1813 for ; Wed, 21 Aug 2019 03:55:22 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D3E422DD3 for ; Wed, 21 Aug 2019 03:55:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="YaNnl+jE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D3E422DD3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hgm-0007d1-BA; Wed, 21 Aug 2019 03:53:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hgl-0007cP-2g for xen-devel@lists.xen.org; Wed, 21 Aug 2019 03:53:35 +0000 X-Inumbo-ID: 374ad56e-c3c7-11e9-ac23-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 374ad56e-c3c7-11e9-ac23-bc764e2007e4; Wed, 21 Aug 2019 03:53:21 +0000 (UTC) Received: from localhost.localdomain (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C98452339F; Wed, 21 Aug 2019 03:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566359600; bh=JaVbeAAX/zwCno/kZQEV2bAAyzSchQxLtpBM7P9idhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YaNnl+jETCIzO6E3AyTTVqV0qV5lZUMOc7Np8r1Lp27Pwr91ISn1ImhSbpnjhsLu0 1EALaP965Yjcxijun/5GqUwvQpuFFkAFsL+r+vMm+L+367WM+SP6si8GYKZVhxN4K5 2JvPoRXdED/2XjUS+FQTHrs01P8tKD2IpK+wYokQ= From: Stefano Stabellini To: julien.grall@arm.com Date: Tue, 20 Aug 2019 20:53:12 -0700 Message-Id: <20190821035315.12812-5-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 5/8] xen/arm: assign devices to boot domains X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, andrii_anisov@epam.com, Achin.Gupta@arm.com, xen-devel@lists.xen.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Scan the user provided dtb fragment at boot. For each device node, map memory to guests, and route interrupts and setup the iommu. The memory region to remap is specified by the "xen,reg" property. The iommu is setup by passing the node of the device to assign on the host device tree. The path is specified in the device tree fragment as the "xen,path" string property. The interrupts are remapped based on the information from the corresponding node on the host device tree. Call handle_device_interrupts to remap interrupts. Interrupts related device tree properties are copied from the device tree fragment, same as all the other properties. Signed-off-by: Stefano Stabellini --- Changes in v4: - use unsigned - improve commit message - code style - use dt_prop_cmp - use device_tree_get_reg - don't copy over xen,reg and xen,path - don't create special interrupt properties for domU: copy them from the fragment - in-code comment Changes in v3: - improve commit message - remove superfluous cast - merge code with the copy code - add interrup-parent - demove depth > 2 check - reuse code from handle_device_interrupts - copy interrupts from host dt Changes in v2: - rename "path" to "xen,path" - grammar fix - use gaddr_to_gfn and maddr_to_mfn - remove depth <= 2 limitation in scanning the dtb fragment - introduce and parse xen,reg - code style - support more than one interrupt per device - specify only the GIC is supported --- xen/arch/arm/domain_build.c | 66 ++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index c71b9f2889..256c83462a 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1721,6 +1721,9 @@ static int __init handle_prop_pfdt(struct kernel_info *kinfo, void *fdt = kinfo->fdt; int propoff, nameoff, res; const struct fdt_property *prop; + struct dt_device_node *node; + const __be32 *cell; + unsigned int i, len; for ( propoff = fdt_first_property_offset(pfdt, nodeoff); propoff >= 0; @@ -1730,10 +1733,65 @@ static int __init handle_prop_pfdt(struct kernel_info *kinfo, return -FDT_ERR_INTERNAL; nameoff = fdt32_to_cpu(prop->nameoff); - res = fdt_property(fdt, fdt_string(pfdt, nameoff), - prop->data, fdt32_to_cpu(prop->len)); - if ( res ) - return res; + + /* xen,reg specifies where to map the MMIO region */ + if ( dt_prop_cmp("xen,reg", fdt_string(pfdt, nameoff)) == 0 ) + { + paddr_t mstart, size, gstart; + cell = (const __be32 *)prop->data; + len = fdt32_to_cpu(prop->len) / + ((address_cells * 2 + size_cells) * sizeof(uint32_t)); + + for ( i = 0; i < len; i++ ) + { + device_tree_get_reg(&cell, address_cells, size_cells, + &mstart, &size); + gstart = dt_next_cell(address_cells, &cell); + + res = guest_physmap_add_entry(kinfo->d, gaddr_to_gfn(gstart), + maddr_to_mfn(mstart), + get_order_from_bytes(size), + p2m_mmio_direct_dev); + if ( res < 0 ) + { + dprintk(XENLOG_ERR, + "Failed to map %"PRIpaddr" to the guest at%"PRIpaddr"\n", + mstart, gstart); + return -EFAULT; + } + } + } + /* + * xen,path specifies the corresponding node in the host DT. + * Both interrupt mappings and IOMMU settings are based on it, + * as they are done based on the corresponding host DT node. + */ + else if ( dt_prop_cmp("xen,path", fdt_string(pfdt, nameoff)) == 0 ) + { + node = dt_find_node_by_path(prop->data); + if ( node == NULL ) + { + dprintk(XENLOG_ERR, "Couldn't find node %s in host_dt!\n", + (char *)prop->data); + return -EINVAL; + } + + res = iommu_assign_dt_device(kinfo->d, node); + if ( res < 0 ) + return res; + + res = handle_device_interrupts(kinfo->d, node, true); + if ( res < 0 ) + return res; + } + /* copy all other properties */ + else + { + res = fdt_property(fdt, fdt_string(pfdt, nameoff), prop->data, + fdt32_to_cpu(prop->len)); + if ( res ) + return res; + } } /* FDT_ERR_NOTFOUND => There is no more properties for this node */ From patchwork Wed Aug 21 03:53:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11105353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB5DA14F7 for ; Wed, 21 Aug 2019 03:55:29 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C807722CF7 for ; Wed, 21 Aug 2019 03:55:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="YMZHuKYa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C807722CF7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hgw-0007ih-Uk; Wed, 21 Aug 2019 03:53:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hgv-0007ho-2a for xen-devel@lists.xen.org; Wed, 21 Aug 2019 03:53:45 +0000 X-Inumbo-ID: 38310b7e-c3c7-11e9-8980-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 38310b7e-c3c7-11e9-8980-bc764e2007e4; Wed, 21 Aug 2019 03:53:22 +0000 (UTC) Received: from localhost.localdomain (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C494233A0; Wed, 21 Aug 2019 03:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566359601; bh=gyG6/+XH1p5WGEkSPidGjTxklArIUKWOhlqW5k25dSs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMZHuKYaHUEIGlBQFrwzLNxqidt/ZPeAEPfh2NWWmCFKwj3oHzsuy9CID5IiHi/bU lNITgXuc8Ohuh+gS1KWVxXpVzIENhZEtWOevWNFnjtldDOWgQVDOp/lzN91jKxEs1Q UdTh9Swo+VYMrarCbkxo6pr4tBvQYtm7/+yg1ysM= From: Stefano Stabellini To: julien.grall@arm.com Date: Tue, 20 Aug 2019 20:53:14 -0700 Message-Id: <20190821035315.12812-7-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 7/8] xen/arm: introduce nr_spis X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, andrii_anisov@epam.com, Achin.Gupta@arm.com, xen-devel@lists.xen.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" We don't have a clear way to know how many virtual SPIs we need for the dom0-less domains. Introduce a new option under xen,domain to specify the number of SPIs to allocate for a domain. The property is optional. When absent, we'll use the physical number of GIC lines for dom0-less domains, just like for dom0. Given that dom0-less VMs are meant for static partitioning scenarios where the number of VMs is very low, increased memory overhead should not be a problem, and it is possible to minimize it using "nr_spis". Remove the old setting of nr_spis based on the presence of the vpl011. Signed-off-by: Stefano Stabellini Reviewed-by: Volodymyr Babchuk --- Changes in v4: - improve commit message Changes in v3: - improve commit message - introduce nr_spis --- xen/arch/arm/domain_build.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 256c83462a..86cbe4e67b 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2280,7 +2280,6 @@ void __init create_domUs(void) struct domain *d; struct xen_domctl_createdomain d_cfg = { .arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE, - .arch.nr_spis = 0, .flags = XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap, .max_evtchn_port = -1, .max_grant_frames = 64, @@ -2290,13 +2289,13 @@ void __init create_domUs(void) if ( !dt_device_is_compatible(node, "xen,domain") ) continue; - if ( dt_property_read_bool(node, "vpl011") ) - d_cfg.arch.nr_spis = GUEST_VPL011_SPI - 32 + 1; - if ( !dt_property_read_u32(node, "cpus", &d_cfg.max_vcpus) ) panic("Missing property 'cpus' for domain %s\n", dt_node_name(node)); + if ( !dt_property_read_u32(node, "nr_spis", &d_cfg.arch.nr_spis) ) + d_cfg.arch.nr_spis = gic_number_lines() - 32; + d = domain_create(++max_init_domid, &d_cfg, false); if ( IS_ERR(d) ) panic("Error creating domain %s\n", dt_node_name(node)); From patchwork Wed Aug 21 03:53:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11105339 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88D7D14F7 for ; Wed, 21 Aug 2019 03:54:54 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5CE6D22DD3 for ; Wed, 21 Aug 2019 03:54:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="1h4DiN7i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5CE6D22DD3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0Hga-0007Xa-9U; Wed, 21 Aug 2019 03:53:24 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0HgZ-0007XV-HN for xen-devel@lists.xen.org; Wed, 21 Aug 2019 03:53:23 +0000 X-Inumbo-ID: 3897caee-c3c7-11e9-adbf-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3897caee-c3c7-11e9-adbf-12813bfff9fa; Wed, 21 Aug 2019 03:53:23 +0000 (UTC) Received: from localhost.localdomain (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 01BD7233A1; Wed, 21 Aug 2019 03:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566359602; bh=cwxXDnVPL4zXfRZjxiRXC0qdOTfTGc+Wr/gkO4W2NMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1h4DiN7iS9x85yZOWiF35Vqq5f4rPRYS7nbjRAGiEAeNFaCYXvqDlV2sW6y4fFCgf M/MRjdADr8RwHiGtQiCMqvXzrsjkGUCYcoVujUYjVrnRUFelyw84g+D2EIVApoX4P7 mYKKEgp07/7+KJ9X/e1Q+aeLG9mZSti6e4byNkPs= From: Stefano Stabellini To: julien.grall@arm.com Date: Tue, 20 Aug 2019 20:53:15 -0700 Message-Id: <20190821035315.12812-8-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v4 8/8] xen/arm: add dom0-less device assignment info to docs X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, andrii_anisov@epam.com, Achin.Gupta@arm.com, xen-devel@lists.xen.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Add info about the SPI used for the virtual pl011. Signed-off-by: Stefano Stabellini --- Changes in v4: - fix spelling - add "multiboot,module" - improve commit message - improve doc - expand the nr_spis and vpl011 sections and include information about the vpl011 SPI - move passthrough information to docs/misc/arm/passthrough.txt Changes in v3: - add nr_spis - change description of interrupts and interrupt-parent Changes in v2: - device tree fragment loaded in cacheable memory - rename multiboot,dtb to multiboot,device-tree - rename "path" to "xen,path" - add a note about device memory mapping - introduce xen,reg - specify only the GIC is supported --- docs/misc/arm/device-tree/booting.txt | 44 ++++++++++- docs/misc/arm/passthrough.txt | 105 ++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-tree/booting.txt index 317a9e962a..0b850c0591 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -146,7 +146,18 @@ with the following properties: - vpl011 - An empty property to enable/disable a virtual pl011 for the guest to use. + An empty property to enable/disable a virtual pl011 for the guest to + use. The virtual pl011 uses SPI number 32 (see GUEST_VPL011_SPI). + Please note that the SPI used for the virtual pl011 could clash with the + physical SPI of a physical device assigned to the guest. + +- nr_spis + + Optional. A 32-bit integer specifying the number of SPIs (Shared + Peripheral Interrupts) to allocate for the domain. If nr_spis is + missing, the max number of SPIs supported by the physical GIC is + used. If both vpl011 and nr_spis are set, nr_spis should be at least + 1 to account for the SPI used by the virtual pl011. - #address-cells and #size-cells @@ -226,3 +237,34 @@ chosen { }; }; }; + + +Device Assignment +================= + +Device Assignment (Passthrough) is supported by adding another module, +alongside the kernel and ramdisk, with the device tree fragment +corresponding to the device node to assign to the guest. + +The dtb sub-node should have the following properties: + +- compatible + + "multiboot,device-tree" and "multiboot,module" + +- reg + + Specifies the physical address of the device tree binary fragment + RAM and its length. + +As an example: + + module@0xc000000 { + compatible = "multiboot,device-tree", "multiboot,module"; + reg = <0x0 0xc000000 0xffffff>; + }; + +The DTB fragment is loaded at 0xc000000 in the example above. It should +follow the convention explained in docs/misc/arm/passthrough.txt. The +DTB fragment will be added to the guest device tree, so that the guest +kernel will be able to discover the device. diff --git a/docs/misc/arm/passthrough.txt b/docs/misc/arm/passthrough.txt index 0efbd122de..8084f2e31b 100644 --- a/docs/misc/arm/passthrough.txt +++ b/docs/misc/arm/passthrough.txt @@ -80,6 +80,111 @@ SPI numbers start from 32, in this example 80 + 32 = 112. See man [xl.cfg] for the iomem format. The reg property is just a pair of address, then size numbers, each of them can occupy 1 or 2 cells. + +Dom0-less Device Passthrough +============================ + +The partial device tree for dom0-less guests should have the following +properties for each node corresponding to a physical device to assign to +the guest: + +- xen,reg + + The xen,reg property is an array of: + + + + They specify the physical address and size of the device memory + ranges together with the corresponding guest address to map them to. + The size of `phys_addr' and `guest_addr' is determined by + #address_cells; the size of `size' is determined by #size_cells. + The memory will be mapped as device memory in the guest + (p2m_mmio_direct_dev). + +- xen,path + + A string property representing the path in the host device tree to the + corresponding device node. + +In addition, a special /gic node is expected as a placeholder for the +full GIC node that will be added by Xen for the guest. /gic can be +referenced by other properties in the device tree fragment. For +instance, it can be referenced by interrupt-parent under a device node. +Xen will take care of substituting the "gic" placeholder node for a +complete GIC node while retaining all the references correctly. + + gic: gic { + #interrupt-cells = <0x3>; + interrupt-controller; + }; + +Note that the #interrupt-cells and interrupt-controller properties are +not actually required, however, DTC expects them to be present if gic is +referenced by interrupt-parent or similar. + + +Example +======= + +The following is a real-world example of a device tree fragment to +assign a network card to a dom0-less guest on Xilinx Ultrascale+ MPSoC: + +/dts-v1/; + +/ { + #address-cells = <0x2>; + #size-cells = <0x1>; + + gic: gic { + #interrupt-cells = <0x3>; + interrupt-controller; + }; + + passthrough { + compatible = "simple-bus"; + ranges; + #address-cells = <0x2>; + #size-cells = <0x1>; + + misc_clk { + #clock-cells = <0x0>; + clock-frequency = <0x7735940>; + compatible = "fixed-clock"; + linux,phandle = <0x1>; + phandle = <0x1>; + }; + + ethernet@ff0e0000 { + compatible = "cdns,zynqmp-gem"; + status = "okay"; + reg = <0x0 0xff0e0000 0x1000>; + clock-names = "pclk", "hclk", "tx_clk", "rx_clk"; + #address-cells = <0x1>; + #size-cells = <0x0>; + clocks = <0x1 0x1 0x1 0x1>; + phy-mode = "rgmii-id"; + xlnx,ptp-enet-clock = <0x0>; + local-mac-address = [00 0a 35 00 22 01]; + phy-handle = <0x2>; + interrupt-parent = <&gic>; + interrupts = <0x0 0x3f 0x4 0x0 0x3f 0x4>; + xen,path = "/amba/ethernet@ff0e0000"; + xen,reg = <0x0 0xff0e0000 0x1000 0x0 0xff0e0000>; + + phy@c { + reg = <0xc>; + ti,rx-internal-delay = <0x8>; + ti,tx-internal-delay = <0xa>; + ti,fifo-depth = <0x1>; + ti,rxctrl-strap-worka; + linux,phandle = <0x2>; + phandle = <0x2>; + }; + }; + }; +}; + + [arm,gic.txt]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/interrupt-controller/arm,gic.txt [arm,gic-v3.txt]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.txt [xl.cfg]: https://xenbits.xen.org/docs/unstable/man/xl.cfg.5.html