From patchwork Thu Aug 8 23:12:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11084943 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 020801398 for ; Thu, 8 Aug 2019 23:14:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5C3D28826 for ; Thu, 8 Aug 2019 23:14:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA1EE28C04; Thu, 8 Aug 2019 23:14:00 +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 7117628826 for ; Thu, 8 Aug 2019 23:14:00 +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 1hvraP-000321-WA; Thu, 08 Aug 2019 23:12:45 +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 1hvraO-00031e-FO for xen-devel@lists.xen.org; Thu, 08 Aug 2019 23:12:44 +0000 X-Inumbo-ID: 06c9864a-ba32-11e9-83ed-cfaf4b1f0b6e Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 06c9864a-ba32-11e9-83ed-cfaf4b1f0b6e; 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 1A4CF216C8; Thu, 8 Aug 2019 23:12:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565305963; bh=2AfmFi7anX+X2pH4+meFLL4fdAtGDXbUKTLHh7lhCbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gdEVdbJC5uFECdN6vYCYDEqeoxemtemaDSsQpYEbDAxL3/Agb7O4yw6EYC6TORHG5 LvDLcDbR9ePV7MLHKBqVldRB9wnTglxxkPPGiBuY/+EEsa/hXwk+1vzJA2rqa6pN5R +fDvI7caPecJ56mwVC/0sBEnSQ0ydKe2JS/wV0+U= From: Stefano Stabellini To: julien.grall@arm.com Date: Thu, 8 Aug 2019 16:12:37 -0700 Message-Id: <20190808231242.26424-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 1/6] xen/arm: introduce handle_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" X-Virus-Scanned: ClamAV using ClamSMTP Move the interrupt handling code out of handle_device to a new function so that it can be reused for dom0less VMs later. Signed-off-by: Stefano Stabellini --- 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_interrupts, and very little else. --- xen/arch/arm/domain_build.c | 79 +++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 4c8404155a..00ddb3b05d 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1220,41 +1220,19 @@ 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 + * Return: + * < 0 on error + * 0 on no mapping required + * 1 IRQ mapping done */ -static int __init handle_device(struct domain *d, struct dt_device_node *dev, - p2m_type_t p2mt) +static int __init handle_interrupts(struct domain *d, + struct dt_device_node *dev, + bool need_mapping) { - unsigned int nirq; - unsigned int naddr; - unsigned int i; - int res; + int i, nirq, 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 +1269,47 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, return res; } + return !!(need_mapping && res == 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_interrupts(d, dev, need_mapping); + if ( res < 0 ) + return res; + /* Give permission and map MMIOs */ for ( i = 0; i < naddr; i++ ) {