From patchwork Thu Aug 8 23:12:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11084949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17D551709 for ; Thu, 8 Aug 2019 23:14:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 061A828826 for ; Thu, 8 Aug 2019 23:14:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC17628C05; Thu, 8 Aug 2019 23:14:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B79228826 for ; Thu, 8 Aug 2019 23:14:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvraS-00033a-JF; Thu, 08 Aug 2019 23:12:48 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvraQ-00032R-PQ for xen-devel@lists.xen.org; Thu, 08 Aug 2019 23:12:46 +0000 X-Inumbo-ID: 0760e6ae-ba32-11e9-8980-bc764e045a96 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 0760e6ae-ba32-11e9-8980-bc764e045a96; Thu, 08 Aug 2019 23:12:44 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.xilinx.com (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 207B921773; Thu, 8 Aug 2019 23:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565305964; bh=YA8x0PXoxSsdIBdwhd2S+w6rYBQWneju6ZMINMYxAxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m+IJUZiS5sE0KoyEFV5DhACuNoE9oDXihwMNOehsBqSByFOu/7vcrbHPypFPL4237 96gfJXGX5QDkcGp2U+8Qh5YgXBsMggI2sal2tWRxpzB2rS16o1jdA+zdggnpwlEimC ip3boX0WwXXDHCV5l1oUZQHzCqfS8dV7w9I/aI8w= From: Stefano Stabellini To: julien.grall@arm.com Date: Thu, 8 Aug 2019 16:12:39 -0700 Message-Id: <20190808231242.26424-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 3/6] 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" X-Virus-Scanned: ClamAV using ClamSMTP Scan the user provided dtb fragment at boot. For each device node, map memory to guests, and route interrupts and setup the iommu. 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 memory region to remap is specified by the "xen,reg" property. (Perhaps it might be possible to use "range" instead of "xen,regs". This is something to investigate.) The interrupts are taken from the host device tree corresponding node. To map the interrupt call handle_interrupts, which is shared with the existing dom0 path. Add a interrupt-parent property automatically to the guest device tree when the interrupt-parent should be the GIC. Copy over the interrupt property from the host device tree node. Signed-off-by: Stefano Stabellini --- 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_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, 66 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 70bcdc449d..0057a509d1 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1712,6 +1712,9 @@ static int __init handle_properties(struct domain *d, void *fdt, const void *pfd { int propoff, nameoff, r; const struct fdt_property *prop; + struct dt_device_node *node; + const __be32 *cell; + int i, len; for ( propoff = fdt_first_property_offset(pfdt, nodeoff); propoff >= 0; @@ -1726,6 +1729,69 @@ static int __init handle_properties(struct domain *d, void *fdt, const void *pfd prop->data, fdt32_to_cpu(prop->len)); if ( r ) return r; + + if ( strcmp("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 (u32)); + + for ( i = 0; i < len; i++ ) + { + mstart = dt_next_cell(address_cells, &cell); + size = dt_next_cell(size_cells, &cell); + gstart = dt_next_cell(address_cells, &cell); + + r = guest_physmap_add_entry(d, gaddr_to_gfn(gstart), + maddr_to_mfn(mstart), + get_order_from_bytes(size), + p2m_mmio_direct_dev); + if ( r < 0 ) + { + dprintk(XENLOG_ERR, + "Failed to map %"PRIpaddr" to the guest at%"PRIpaddr"\n", + mstart, gstart); + return -EFAULT; + } + } + } + + if ( strcmp("xen,path", fdt_string(pfdt, nameoff)) == 0 ) + { + node = dt_find_node_by_path(prop->data); + if ( node != NULL ) + r = iommu_assign_dt_device(d, node); + else + { + dprintk(XENLOG_ERR, "Couldn't find node %s in host_dt!\n", + (char *)prop->data); + return -EINVAL; + } + + r = handle_interrupts(d, node, true); + if ( r < 0 ) + return r; + if ( r > 0 ) + { + unsigned int intlen; + const u32* intspec; + + /* generate interrupt-parent to point to the virtual GIC */ + r = fdt_property_u32(fdt, "interrupt-parent", GUEST_PHANDLE_GIC); + if ( r ) + return r; + + /* copy interrupts/interrupts-extended from the host DT node */ + intspec = dt_get_property(node, "interrupts", &intlen); + if ( intspec == NULL ) + return -EFAULT; + + r = fdt_property(fdt, "interrupts", intspec, intlen); + if ( r ) + return r; + } + } } /* FDT_ERR_NOTFOUND => There is no more properties for this node */