From patchwork Thu Oct 3 01:35:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11171979 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 AF748139A for ; Thu, 3 Oct 2019 01:36:42 +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 8B42D222BE for ; Thu, 3 Oct 2019 01:36:42 +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="bpnP+YKM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B42D222BE 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 1iFq1k-0003Xa-2p; Thu, 03 Oct 2019 01:35: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 1iFq1i-0003XQ-Kq for xen-devel@lists.xen.org; Thu, 03 Oct 2019 01:35:30 +0000 X-Inumbo-ID: 15330054-e57e-11e9-97fb-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by localhost (Halon) with ESMTPS id 15330054-e57e-11e9-97fb-bc764e2007e4; Thu, 03 Oct 2019 01:35:30 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 9486C222BE; Thu, 3 Oct 2019 01:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570066529; bh=HaY4kOXVJcylrsj+hflyHE8r5f9X6kHzwd1zKTdDOQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpnP+YKMbjFOO0we6M53/eAcXLWOYyuL9xO2+dXOGsZKNUqp7oVWksehQV6Rw//GP bcETmiRBA2qbmf5uQkg7wIgqmcmA9l0z8XILq1oeZYJuxAZA6mY6hYSM5MYt7GW2cG 2b7thYMg8Ba9MLwZpbMQA0B9X1dCxJF0rgZYyOho= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 2 Oct 2019 18:35:19 -0700 Message-Id: <20191003013526.30768-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v8 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 | 100 ++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 39 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 337a89e518..fb356603e2 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1238,6 +1238,62 @@ static int __init map_device_children(struct domain *d, return 0; } +/* + * 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_interrupts(struct domain *d, + struct dt_device_node *dev, + bool need_mapping) +{ + unsigned int i, nirq; + int res; + struct dt_raw_irq rirq; + + nirq = dt_number_of_irq(dev); + + /* Give permission and map IRQs */ + for ( i = 0; i < nirq; i++ ) + { + res = dt_device_get_raw_irq(dev, i, &rirq); + if ( res ) + { + printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + /* + * Don't map IRQ that have no physical meaning + * ie: IRQ whose controller is not the GIC + */ + if ( rirq.controller != dt_interrupt_controller ) + { + dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", + i, dt_node_full_name(rirq.controller)); + continue; + } + + res = platform_get_irq(dev, i); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to get irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); + if ( res ) + return res; + } + + return 0; +} + /* * For a given device node: * - Give permission to the guest to manage IRQ and MMIO range @@ -1250,19 +1306,16 @@ static int __init map_device_children(struct domain *d, static int __init handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) { - unsigned int nirq; unsigned int naddr; unsigned int i; 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); + dt_dprintk("%s passthrough = %d naddr = %u\n", + dt_node_full_name(dev), need_mapping, naddr); if ( need_mapping ) { @@ -1290,40 +1343,9 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, } } - /* Give permission and map IRQs */ - for ( i = 0; i < nirq; i++ ) - { - res = dt_device_get_raw_irq(dev, i, &rirq); - if ( res ) - { - printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - /* - * Don't map IRQ that have no physical meaning - * ie: IRQ whose controller is not the GIC - */ - if ( rirq.controller != dt_interrupt_controller ) - { - dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", - i, dt_node_full_name(rirq.controller)); - continue; - } - - res = platform_get_irq(dev, i); - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to get irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); - if ( res ) - 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 Thu Oct 3 01:35:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11171983 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 C8C6513BD for ; Thu, 3 Oct 2019 01:36:48 +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 A5352222BE for ; Thu, 3 Oct 2019 01:36:48 +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="UvF14dIH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5352222BE 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 1iFq1o-0003ZK-S9; Thu, 03 Oct 2019 01:35: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 1iFq1n-0003Z0-MF for xen-devel@lists.xen.org; Thu, 03 Oct 2019 01:35:35 +0000 X-Inumbo-ID: 1574a1ee-e57e-11e9-bf31-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by localhost (Halon) with ESMTPS id 1574a1ee-e57e-11e9-bf31-bc764e2007e4; Thu, 03 Oct 2019 01:35:30 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 7BF1A222C3; Thu, 3 Oct 2019 01:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570066529; bh=oioZ80YmDh5BZ2RY3omy5UQgF74fXkxFb7JblL6TNrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UvF14dIHD06P69YGcCoVTsWay6B9NZjuwjZYD0YTs/Bk9Bd4zV9wy4Xvwn7IboEmp gxkBQIhsLTb3fE24ZHWAzX9nJ2j3w2y7COy+C+NCu2pEmeO2P/UDm2zlRmYdq3E6sS siAFVfl2joDkLWeT8IOmnmVcjzFlNk+epUoxR/k0= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 2 Oct 2019 18:35:20 -0700 Message-Id: <20191003013526.30768-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v8 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 Acked-by: Julien Grall --- Changes in v5: - move declarations to xen/include/asm-arm/setup.h Changes in v4: - new patch --- xen/arch/arm/bootfdt.c | 8 ++++---- xen/include/asm-arm/setup.h | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 623173bc7f..a7810abb15 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/asm-arm/setup.h b/xen/include/asm-arm/setup.h index efcba545c2..fa0a8721b2 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -115,6 +115,12 @@ const char *boot_module_kind_as_string(bootmodule_kind kind); extern uint32_t hyp_traps_vector[]; void init_traps(void); +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); + #endif /* * Local variables: From patchwork Thu Oct 3 01:35:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11171981 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 B3B7313BD for ; Thu, 3 Oct 2019 01:36:46 +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 8FE78222BE for ; Thu, 3 Oct 2019 01:36:46 +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="n3Dp64X4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FE78222BE 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 1iFq1m-0003YA-CX; Thu, 03 Oct 2019 01:35:34 +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 1iFq1k-0003Xo-Ft for xen-devel@lists.xen.org; Thu, 03 Oct 2019 01:35:32 +0000 X-Inumbo-ID: 163fa592-e57e-11e9-971d-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by localhost (Halon) with ESMTPS id 163fa592-e57e-11e9-971d-12813bfff9fa; Thu, 03 Oct 2019 01:35:31 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 E5B20222C4; Thu, 3 Oct 2019 01:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570066531; bh=4P9vHs+x0x+Ba1j0nqm9pex9XW2hcInSe5HSIg/Na7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3Dp64X4q+8F8SXyM4/fyviyRBnIZA2Wjh4ArAxfT1pP6pgS3e4XA3l+Ol755Cfm+ jchEujb9FaTvo0Q/4U0ymwmdktcaC3+6t91CKxYD9jpj2VhUvPN1JZM2w+n8JEvKZ5 VwcHs7C2Hh5KjMx53inYJGiZdfd68W8OdO9aIjcM= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 2 Oct 2019 18:35:21 -0700 Message-Id: <20191003013526.30768-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v8 3/8] xen/arm: introduce kinfo->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. Remove the fdt pointer argument to the make_*_domU_node functions and oass a struct kernel_info * instead. The fdt pointer can be accessed from kinfo->fdt. Remove the struct domain *d parameter to the make_*_domU_node functions because it becomes unused. Initialize phandle_gic to GUEST_PHANDLE_GIC at the beginning of prepare_dtb_domU for DomUs. Later patches will change the value of phandle_gic depending on user provided information. For Dom0, initialize phandle_gic to dt_interrupt_controller->phandle (current value) at the beginning of prepare_dtb. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v6: - rename guest_phandle_gic to phandle_gic - use phandle_gic for dom0 too Changes in v5: - improve commit message Changes in v4: - new patch --- xen/arch/arm/domain_build.c | 39 ++++++++++++++++++++---------------- xen/include/asm-arm/kernel.h | 3 +++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index fb356603e2..d23c0a9b87 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -626,15 +626,14 @@ static int __init fdt_property_interrupts(const struct kernel_info *kinfo, unsigned num_irq) { int res; - uint32_t phandle = is_hardware_domain(kinfo->d) ? - dt_interrupt_controller->phandle : GUEST_PHANDLE_GIC; res = fdt_property(kinfo->fdt, "interrupts", intr, sizeof(intr[0]) * num_irq); if ( res ) return res; - res = fdt_property_cell(kinfo->fdt, "interrupt-parent", phandle); + res = fdt_property_cell(kinfo->fdt, "interrupt-parent", + kinfo->phandle_gic); return res; } @@ -1552,8 +1551,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; @@ -1588,11 +1588,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->phandle_gic); if (res) return res; - res = fdt_property_cell(fdt, "phandle", GUEST_PHANDLE_GIC); + res = fdt_property_cell(fdt, "phandle", kinfo->phandle_gic); if (res) return res; @@ -1601,8 +1601,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; @@ -1637,11 +1638,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->phandle_gic); if (res) return res; - res = fdt_property_cell(fdt, "phandle", GUEST_PHANDLE_GIC); + res = fdt_property_cell(fdt, "phandle", kinfo->phandle_gic); if (res) return res; @@ -1650,22 +1651,23 @@ 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"); } } #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]; @@ -1696,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->phandle_gic); if ( res ) return res; @@ -1721,6 +1723,8 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) int addrcells, sizecells; int ret; + kinfo->phandle_gic = GUEST_PHANDLE_GIC; + addrcells = GUEST_ROOT_ADDRESS_CELLS; sizecells = GUEST_ROOT_SIZE_CELLS; @@ -1764,7 +1768,7 @@ 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; @@ -1776,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; @@ -1808,6 +1812,7 @@ static int __init prepare_dtb_hwdom(struct domain *d, struct kernel_info *kinfo) ASSERT(dt_host && (dt_host->sibling == NULL)); + kinfo->phandle_gic = dt_interrupt_controller->phandle; fdt = device_tree_flattened; new_size = fdt_totalsize(fdt) + DOM0_FDT_EXTRA_SIZE; diff --git a/xen/include/asm-arm/kernel.h b/xen/include/asm-arm/kernel.h index 33f3e72b11..43fa87545e 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 phandle_gic; + /* loader to use for this kernel */ void (*load)(struct kernel_info *info); /* loader specific state */ From patchwork Thu Oct 3 01:35:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11171985 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 35D9A139A for ; Thu, 3 Oct 2019 01:36:52 +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 069C8222BE for ; Thu, 3 Oct 2019 01:36:52 +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="bY2d3kir" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 069C8222BE 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 1iFq1r-0003aS-60; Thu, 03 Oct 2019 01:35:39 +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 1iFq1p-0003Zm-EE for xen-devel@lists.xen.org; Thu, 03 Oct 2019 01:35:37 +0000 X-Inumbo-ID: 176182c4-e57e-11e9-971d-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by localhost (Halon) with ESMTPS id 176182c4-e57e-11e9-971d-12813bfff9fa; Thu, 03 Oct 2019 01:35:33 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 6A246222C2; Thu, 3 Oct 2019 01:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570066533; bh=IefElVA/5GkbLDN2pjRIoYjGK0hKZ18rf9bQCZd0zV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bY2d3kircyvcaLWrRTZs7tWMlpFfIhfBaSALAjdKYLOiJdu2eINFiMe0/8HBNzDfX ZonrQhgW9fwkPW42pHHZFPDSWHIvXxdjnGOQ+YZWdx+pmwPGecM+uajbnar7U63Zjo eTFWjcoNACCmhw7P12OJg7Vf4aGLb92OgqyXKv6Q= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 2 Oct 2019 18:35:22 -0700 Message-Id: <20191003013526.30768-4-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v8 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->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. scan_passthrough_prop is introduced here and not used in this patch but it will be used by later patches. 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 Acked-by: Julien Grall ---- Changes in v6: - code style - in-code comment - commit message improvements Changes in v5: - code style - in-code comment - remove depth parameter from scan_pfdt_node - for instead of loop in domain_handle_dtb_bootmodule - move "gic" check to domain_handle_dtb_bootmodule - add check_partial_fdt - use DT_ROOT_NODE_ADDR/SIZE_CELLS_DEFAULT - add scan_passthrough_prop parameter, set it to false for "/aliases" 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 | 164 +++++++++++++++++++++++++++++++++++ xen/include/asm-arm/kernel.h | 2 +- 2 files changed, 165 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d23c0a9b87..84b65b8f25 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,157 @@ 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, + bool scan_passthrough_prop) +{ + 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, + uint32_t address_cells, uint32_t size_cells, + bool scan_passthrough_prop) +{ + int rc = 0; + void *fdt = kinfo->fdt; + int node_next; + + 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, + scan_passthrough_prop); + if ( rc ) + return rc; + + address_cells = device_tree_get_u32(pfdt, nodeoff, "#address-cells", + DT_ROOT_NODE_ADDR_CELLS_DEFAULT); + size_cells = device_tree_get_u32(pfdt, nodeoff, "#size-cells", + DT_ROOT_NODE_SIZE_CELLS_DEFAULT); + + node_next = fdt_first_subnode(pfdt, nodeoff); + while ( node_next > 0 ) + { + scan_pfdt_node(kinfo, pfdt, node_next, address_cells, size_cells, + scan_passthrough_prop); + node_next = fdt_next_subnode(pfdt, node_next); + } + + return fdt_end_node(fdt); +} + +static int __init check_partial_fdt(void *pfdt, size_t size) +{ + int res; + + if ( fdt_magic(pfdt) != FDT_MAGIC ) + { + dprintk(XENLOG_ERR, "Partial FDT is not a valid Flat Device Tree"); + return -EINVAL; + } + + res = fdt_check_header(pfdt); + if ( res ) + { + dprintk(XENLOG_ERR, "Failed to check the partial FDT (%d)", res); + return -EINVAL; + } + + if ( fdt_totalsize(pfdt) > size ) + { + dprintk(XENLOG_ERR, "Partial FDT totalsize is too big"); + return -EINVAL; + } + + return 0; +} + +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; + + res = check_partial_fdt(pfdt, kinfo->dtb_bootmodule->size); + if ( res < 0 ) + return res; + + for ( node_next = fdt_first_subnode(pfdt, 0); + node_next > 0; + node_next = fdt_next_subnode(pfdt, node_next) ) + { + const char *name = fdt_get_name(pfdt, node_next, NULL); + + if ( name == NULL ) + continue; + + /* + * Only scan /gic /aliases /passthrough, ignore the rest. + * They don't have to be parsed in order. + * + * Take the GIC phandle value from the special /gic node in the + * DTB fragment. + */ + if ( dt_node_cmp(name, "gic") == 0 ) + { + kinfo->phandle_gic = fdt_get_phandle(pfdt, node_next); + continue; + } + + if ( dt_node_cmp(name, "aliases") == 0 ) + { + res = scan_pfdt_node(kinfo, pfdt, node_next, + DT_ROOT_NODE_ADDR_CELLS_DEFAULT, + DT_ROOT_NODE_SIZE_CELLS_DEFAULT, + false); + if ( res ) + return res; + continue; + } + if ( dt_node_cmp(name, "passthrough") == 0 ) + { + res = scan_pfdt_node(kinfo, pfdt, node_next, + DT_ROOT_NODE_ADDR_CELLS_DEFAULT, + DT_ROOT_NODE_SIZE_CELLS_DEFAULT, + true); + if ( res ) + return res; + continue; + } + } + + 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 +1920,18 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) if ( ret ) goto err; + /* + * domain_handle_dtb_bootmodule has to be called before the rest of + * the device tree is generated because it depends on the value of + * the field phandle_gic. + */ + 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 43fa87545e..874aa108a7 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 Thu Oct 3 01:35:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11171987 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 568F913BD for ; Thu, 3 Oct 2019 01:36: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 272C0222C2 for ; Thu, 3 Oct 2019 01:36: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="VUl8ly4t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 272C0222C2 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 1iFq1u-0003cJ-HR; Thu, 03 Oct 2019 01:35:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iFq1s-0003bM-MR for xen-devel@lists.xen.org; Thu, 03 Oct 2019 01:35:40 +0000 X-Inumbo-ID: 17b4c1c8-e57e-11e9-97fb-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by localhost (Halon) with ESMTPS id 17b4c1c8-e57e-11e9-97fb-bc764e2007e4; Thu, 03 Oct 2019 01:35:34 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 2D2CC222C5; Thu, 3 Oct 2019 01:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570066533; bh=3GTa12ziuCyhFNf04MqnpMYV5qf2NOy0Pn59S8hTOb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VUl8ly4t1HMpiYM5IuiZ93mrDjYpFEa0qDFhvhcyaaBwdpVUtBAzC5JXsKAe1zQ7Z 0X5M+FYrQ9NMDHQbV36xK4VpFgpIxOJaNaT4urBl63ZXk6tdIRJOLfNZbBwrTc3tEW US1gNDhTueAJYwmdQ9k7S5tYauQ1SOnIso6yYvmo= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 2 Oct 2019 18:35:23 -0700 Message-Id: <20191003013526.30768-5-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v8 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. Require both xen,reg and xen,path to be present, unless xen,force-assign-without-iommu is also set. In that case, tolerate a missing xen,path, also tolerate iommu setup failure for the passthrough device. Also set add the new flag XEN_DOMCTL_CDF_iommu so that dom0less domU can use the IOMMU if a partial dtb is specified. Signed-off-by: Stefano Stabellini --- Changes in v8: - better in-code comment - code style - add a prink in case of error Changes in v7: - improve in-code comment - code style - return 1 instead of ENOENT - introduce "xen,force-assign-without-iommu" - require both "xen,reg" and "xen,path" unless "xen,force-assign-without-iommu" Changes in v6: - turn dprintks into printks - return error on page alignment check failure - set XEN_DOMCTL_CDF_iommu if partial dtb is specified Changes in v5: - use local variable for name - use map_regions_p2mt - add warning for not page aligned addresses/sizes - introduce handle_passthrough_prop 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 | 139 ++++++++++++++++++++++++++++++++++-- 1 file changed, 135 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 84b65b8f25..b90902ad97 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1714,6 +1714,88 @@ static int __init make_vpl011_uart_node(struct kernel_info *kinfo) } #endif +/* + * Scan device tree properties for passthrough specific information. + * Returns < 0 on error + * 0 on success + */ +static int __init handle_passthrough_prop(struct kernel_info *kinfo, + const struct fdt_property *xen_reg, + const struct fdt_property *xen_path, + bool xen_force, + uint32_t address_cells, uint32_t size_cells) +{ + const __be32 *cell; + unsigned int i, len; + struct dt_device_node *node; + int res; + paddr_t mstart, size, gstart; + + /* xen,reg specifies where to map the MMIO region */ + cell = (const __be32 *)xen_reg->data; + len = fdt32_to_cpu(xen_reg->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); + + if ( gstart & ~PAGE_MASK || mstart & ~PAGE_MASK || size & ~PAGE_MASK ) + { + printk(XENLOG_ERR + "DomU passthrough config has not page aligned addresses/sizes\n"); + return -EINVAL; + } + + res = map_regions_p2mt(kinfo->d, + gaddr_to_gfn(gstart), + PFN_DOWN(size), + maddr_to_mfn(mstart), + p2m_mmio_direct_dev); + if ( res < 0 ) + { + printk(XENLOG_ERR + "Failed to map %"PRIpaddr" to the guest at%"PRIpaddr"\n", + mstart, gstart); + return -EFAULT; + } + } + + /* + * If xen_force, we let the user assign a MMIO region with no + * associated path. + */ + if ( xen_path == NULL ) + return xen_force ? 0 : -EINVAL; + + /* + * 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. + */ + node = dt_find_node_by_path(xen_path->data); + if ( node == NULL ) + { + printk(XENLOG_ERR "Couldn't find node %s in host_dt!\n", + (char *)xen_path->data); + return -EINVAL; + } + + res = handle_device_interrupts(kinfo->d, node, true); + if ( res < 0 ) + return res; + + /* If xen_force, we ignore IOMMU failures. */ + res = iommu_add_dt_device(node); + if ( res < 0 ) + return xen_force ? 0 : -EINVAL; + + res = iommu_assign_dt_device(kinfo->d, node); + return res; +} + static int __init handle_prop_pfdt(struct kernel_info *kinfo, const void *pfdt, int nodeoff, uint32_t address_cells, uint32_t size_cells, @@ -1721,7 +1803,9 @@ static int __init handle_prop_pfdt(struct kernel_info *kinfo, { void *fdt = kinfo->fdt; int propoff, nameoff, res; - const struct fdt_property *prop; + const struct fdt_property *prop, *xen_reg = NULL, *xen_path = NULL; + const char *name; + bool found, xen_force = false; for ( propoff = fdt_first_property_offset(pfdt, nodeoff); propoff >= 0; @@ -1730,11 +1814,55 @@ static int __init handle_prop_pfdt(struct kernel_info *kinfo, if ( !(prop = fdt_get_property_by_offset(pfdt, propoff, NULL)) ) return -FDT_ERR_INTERNAL; + found = false; nameoff = fdt32_to_cpu(prop->nameoff); - res = fdt_property(fdt, fdt_string(pfdt, nameoff), - prop->data, fdt32_to_cpu(prop->len)); - if ( res ) + name = fdt_string(pfdt, nameoff); + + if ( scan_passthrough_prop ) + { + if ( dt_prop_cmp("xen,reg", name) == 0 ) + { + xen_reg = prop; + found = true; + } + else if ( dt_prop_cmp("xen,path", name) == 0 ) + { + xen_path = prop; + found = true; + } + else if ( dt_prop_cmp("xen,force-assign-without-iommu", + name) == 0 ) + { + xen_force = true; + found = true; + } + } + + /* + * Copy properties other than the ones above: xen,reg, xen,path, + * and xen,force-assign-without-iommu. + */ + if ( !found ) + { + res = fdt_property(fdt, name, prop->data, fdt32_to_cpu(prop->len)); + if ( res ) + return res; + } + } + + /* + * Only handle passthrough properties if both xen,reg and xen,path + * are present, or if xen,force-assign-without-iommu is specified. + */ + if ( xen_reg != NULL && (xen_path != NULL || xen_force) ) + { + res = handle_passthrough_prop(kinfo, xen_reg, xen_path, xen_force, + address_cells, size_cells); + if ( res < 0 ) + { + printk(XENLOG_ERR "Failed to assign device to %pd\n", kinfo->d); return res; + } } /* FDT_ERR_NOTFOUND => There is no more properties for this node */ @@ -2291,6 +2419,9 @@ void __init create_domUs(void) panic("Missing property 'cpus' for domain %s\n", dt_node_name(node)); + if ( dt_find_compatible_node(node, NULL, "multiboot,device-tree") ) + d_cfg.flags |= XEN_DOMCTL_CDF_iommu; + 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 Thu Oct 3 01:35:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11171989 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 A11AF13BD for ; Thu, 3 Oct 2019 01:36: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 7D313222BE for ; Thu, 3 Oct 2019 01:36: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="b6ETDssO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D313222BE 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 1iFq1v-0003dG-Sm; Thu, 03 Oct 2019 01:35:43 +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 1iFq1u-0003cD-Gr for xen-devel@lists.xen.org; Thu, 03 Oct 2019 01:35:42 +0000 X-Inumbo-ID: 176182c5-e57e-11e9-971d-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by localhost (Halon) with ESMTPS id 176182c5-e57e-11e9-971d-12813bfff9fa; Thu, 03 Oct 2019 01:35:34 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 AEF86222C6; Thu, 3 Oct 2019 01:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570066534; bh=+QjoqJzXGXB0pbE8aMyDfA+XpIbLg/CESMqysxlGCE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b6ETDssOAL5qnlOb25QOeeaXXklx93zAxjtAtw+tedRi1kSt1WLYIS3yv6dT2naZC s02wO4GauRJRyDLPCd8yQ3cEShCqLZ3JFg5pDZFXuNwd2Z7jqMXZxWquGaSSWN0TP4 xBUTHtPbeSyObD7WlwS6Esc6nHWpUT7BW4dd1q8M= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 2 Oct 2019 18:35:24 -0700 Message-Id: <20191003013526.30768-6-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v8 6/8] xen/arm: handle "multiboot, device-tree" compatible nodes 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" Detect "multiboot,device-tree" compatible nodes. Add them to the bootmod array as BOOTMOD_GUEST_DTB. In kernel_probe, find the right BOOTMOD_GUEST_DTB and store a pointer to it in dtb_bootmodule. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v4: - use uint32_t - remove useless 0 initialization - add return value check Changes in v2: - rename BOOTMOD_DTB to BOOTMOD_GUEST_DTB - rename multiboot,dtb to multiboot,device-tree --- xen/arch/arm/bootfdt.c | 2 ++ xen/arch/arm/kernel.c | 14 +++++++++++++- xen/arch/arm/setup.c | 1 + xen/include/asm-arm/setup.h | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index a7810abb15..08fb59f4e7 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -242,6 +242,8 @@ static void __init process_multiboot_node(const void *fdt, int node, kind = BOOTMOD_RAMDISK; else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0 ) kind = BOOTMOD_XSM; + else if ( fdt_node_check_compatible(fdt, node, "multiboot,device-tree") == 0 ) + kind = BOOTMOD_GUEST_DTB; else kind = BOOTMOD_UNKNOWN; diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 389bef2afa..8eff074836 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -425,7 +425,7 @@ int __init kernel_probe(struct kernel_info *info, struct bootmodule *mod = NULL; struct bootcmdline *cmd = NULL; struct dt_device_node *node; - u64 kernel_addr, initrd_addr, size; + u64 kernel_addr, initrd_addr, dtb_addr, size; int rc; /* domain is NULL only for the hardware domain */ @@ -469,6 +469,18 @@ int __init kernel_probe(struct kernel_info *info, info->initrd_bootmodule = boot_module_find_by_addr_and_kind( BOOTMOD_RAMDISK, initrd_addr); } + else if ( dt_device_is_compatible(node, "multiboot,device-tree") ) + { + uint32_t len; + const __be32 *val; + + val = dt_get_property(node, "reg", &len); + if ( val == NULL ) + continue; + dt_get_range(&val, node, &dtb_addr, &size); + info->dtb_bootmodule = boot_module_find_by_addr_and_kind( + BOOTMOD_GUEST_DTB, dtb_addr); + } else continue; } diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 790eab94d6..705a917abf 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -369,6 +369,7 @@ const char * __init boot_module_kind_as_string(bootmodule_kind kind) case BOOTMOD_KERNEL: return "Kernel"; case BOOTMOD_RAMDISK: return "Ramdisk"; case BOOTMOD_XSM: return "XSM"; + case BOOTMOD_GUEST_DTB: return "DTB"; case BOOTMOD_UNKNOWN: return "Unknown"; default: BUG(); } diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h index fa0a8721b2..2f8f24e286 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -16,6 +16,7 @@ typedef enum { BOOTMOD_KERNEL, BOOTMOD_RAMDISK, BOOTMOD_XSM, + BOOTMOD_GUEST_DTB, BOOTMOD_UNKNOWN } bootmodule_kind; From patchwork Thu Oct 3 01:35:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11171991 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 6858D139A for ; Thu, 3 Oct 2019 01:37:00 +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 43C99222BE for ; Thu, 3 Oct 2019 01:37:00 +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="cq54bjvm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43C99222BE 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 1iFq21-0003gm-EY; Thu, 03 Oct 2019 01:35:49 +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 1iFq1z-0003fi-Ga for xen-devel@lists.xen.org; Thu, 03 Oct 2019 01:35:47 +0000 X-Inumbo-ID: 18d1d15e-e57e-11e9-971d-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by localhost (Halon) with ESMTPS id 18d1d15e-e57e-11e9-971d-12813bfff9fa; Thu, 03 Oct 2019 01:35:36 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 9F382222BE; Thu, 3 Oct 2019 01:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570066535; bh=FSQX2kDJkRqb0Z9X/id1SGjzmDSr7+bfo6Benr7Wpzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cq54bjvmXMM6XrT0kgzbxnZ4NjRQRyvUtqg5bK9GvUU2efTX2MQF+JVxyGwOsKDor HpXFUUhZpKttcmoJsyQSo5Wjke4lcfGQRk1a3e1iXUBCTxI5GN47GCsgpnvZ9UbGxl PDYJsWZxAuaT9qh7Nl9ipA6yMNUf6kqWcgNn8OLg= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 2 Oct 2019 18:35:25 -0700 Message-Id: <20191003013526.30768-7-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v8 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, or GUEST_VPL011_SPI+1 if vpl011 is requested, whichever is greater. Remove the old setting of nr_spis based on the presence of the vpl011. The implication of this change is that without nr_spis dom0less domains get the same amount of SPI allocated as dom0, regardless of how many physical devices they have assigned, and regardless of whether they have a virtual pl011 (which also needs an emulated SPI). This is done because the SPIs allocation needs to be done before parsing any passthrough information, so we have to account for any potential physical SPI assigned to the domain. When nr_spis is present, the domain gets exactly nr_spis allocated SPIs. If the number is too low, it might not be enough for the devices assigned it to it. If the number is less than GUEST_VPL011_SPI, the virtual pl011 won't work. Signed-off-by: Stefano Stabellini Reviewed-by: Volodymyr Babchuk Acked-by: Julien Grall --- Changes in v5: - improve commit message - allocate enough SPIs for vpl011 Changes in v4: - improve commit message Changes in v3: - improve commit message - introduce nr_spis --- xen/arch/arm/domain_build.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index b90902ad97..5c8d8cd9ce 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2402,7 +2402,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 | XEN_DOMCTL_CDF_hap, .max_evtchn_port = -1, .max_grant_frames = 64, @@ -2412,9 +2411,6 @@ 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)); @@ -2422,6 +2418,19 @@ void __init create_domUs(void) if ( dt_find_compatible_node(node, NULL, "multiboot,device-tree") ) d_cfg.flags |= XEN_DOMCTL_CDF_iommu; + if ( !dt_property_read_u32(node, "nr_spis", &d_cfg.arch.nr_spis) ) + { + d_cfg.arch.nr_spis = gic_number_lines() - 32; + + /* + * vpl011 uses one emulated SPI. If vpl011 is requested, make + * sure that we allocate enough SPIs for it. + */ + if ( dt_property_read_bool(node, "vpl011") ) + d_cfg.arch.nr_spis = MAX(d_cfg.arch.nr_spis, + GUEST_VPL011_SPI - 32 + 1); + } + 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 Thu Oct 3 01:35:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11171995 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 605B413BD for ; Thu, 3 Oct 2019 01:37:06 +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 3C518222BE for ; Thu, 3 Oct 2019 01:37:06 +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="IelNuad8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C518222BE 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 1iFq24-0003jM-Q9; Thu, 03 Oct 2019 01:35:52 +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 1iFq24-0003j5-Eq for xen-devel@lists.xen.org; Thu, 03 Oct 2019 01:35:52 +0000 X-Inumbo-ID: 1a2f6391-e57e-11e9-971d-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by localhost (Halon) with ESMTPS id 1a2f6391-e57e-11e9-971d-12813bfff9fa; Thu, 03 Oct 2019 01:35:38 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 91E3D222C3; Thu, 3 Oct 2019 01:35:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570066538; bh=1xWwpES9nhtB0ZlGxDbrbZiX3cEcb7ulrb2c3OZatNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IelNuad8be2fz4duH6vT/LGGBU8Yh4oH9qWRtgrkGQmdSIipXT7WdLxMCcvvAsk/k ygkEo1nC3n96f9kyWCYyTc764veG5VkXAbpj3+olre1etOw4jlskuyTgrws5XiE0ch 0lVcnYzd7FO0piQHh3Kyks/hgaVAhczTfq20yyNc= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 2 Oct 2019 18:35:26 -0700 Message-Id: <20191003013526.30768-8-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v8 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 Acked-by: Julien Grall --- Changes in v8: - remove sentence about xen,path being optional Changes in v7: - add xen,force-assign-without-iommu - clarify xen,reg and xen,path go together - remove acked-by due to changes Changes in v6: - fix nr_spis description - add ack Changes in v5: - improve wording 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 | 106 ++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-tree/booting.txt index 317a9e962a..649e00d09f 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 0 (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, or GUEST_VPL011_SPI+1 if vpl011 is enabled, whichever is + greater. - #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..6826e1f341 100644 --- a/docs/misc/arm/passthrough.txt +++ b/docs/misc/arm/passthrough.txt @@ -80,6 +80,112 @@ 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, of + the partial device tree. + The memory will be mapped as device memory in the guest (Device-nGnRE). + +- xen,path + + A string property representing the path in the host device tree to the + corresponding device node. + +- xen,force-assign-without-iommu + If xen,force-assign-without-iommu is present Xen continues booting + even on IOMMU setup errors for the device (i.e. the device is not + protected by an IOMMU). + +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 replacing the "gic" placeholder node for a +complete GIC node while retaining all the references correctly. The new +GIC node created by Xen is a regular interrupt-controller@ node. + + 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 = <2>; + #size-cells = <1>; + + gic: gic { + #interrupt-cells = <3>; + interrupt-controller; + }; + + passthrough { + compatible = "simple-bus"; + ranges; + #address-cells = <2>; + #size-cells = <1>; + + misc_clk: misc_clk { + #clock-cells = <0>; + clock-frequency = <0x7735940>; + compatible = "fixed-clock"; + }; + + ethernet@ff0e0000 { + compatible = "cdns,zynqmp-gem"; + status = "okay"; + reg = <0x0 0xff0e0000 0x1000>; + clock-names = "pclk", "hclk", "tx_clk", "rx_clk"; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&misc_clk &misc_clk &misc_clk &misc_clk>; + phy-mode = "rgmii-id"; + xlnx,ptp-enet-clock = <0>; + local-mac-address = [00 0a 35 00 22 01]; + interrupt-parent = <&gic>; + interrupts = <0 63 0x4 0 63 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; + }; + }; + }; +}; + + [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