From patchwork Fri Aug 2 16:39:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 11073911 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 6FA761399 for ; Fri, 2 Aug 2019 16:41:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 603F428898 for ; Fri, 2 Aug 2019 16:41:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54A48287DB; Fri, 2 Aug 2019 16:41:41 +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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 DCFC728897 for ; Fri, 2 Aug 2019 16:41:40 +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 1htab8-0004EO-3i; Fri, 02 Aug 2019 16:40:06 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htab6-00045a-K6 for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 16:40:04 +0000 X-Inumbo-ID: 2ce3f0c6-b544-11e9-8980-bc764e045a96 Received: from mail-lj1-x242.google.com (unknown [2a00:1450:4864:20::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2ce3f0c6-b544-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 16:40:03 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id m8so39844750lji.7 for ; Fri, 02 Aug 2019 09:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lrPG3Jo0g8IN2TUDjww3PLkkrQlh1VPumDr3dhWVCkk=; b=AzXW2EXtSUupxXxNaZI/YiFCMQp5KsnR3CSGBrX0/FWxjqteAg/NJcHGoV39p22wEK ZD1MTM7ntirqrOURfmnyLK9VYfVZ4QjVVWA3GSZixvoqzQluRbL5NDAcZfI4533z/yg6 nwC16orac8Zixl0zqjfcbcoTuTGHcqiW2M+/bGQ0VwczyuHcclR58k/nq4Ue1ksvM9Di s7JdMSCJ5Snb+aRGsVS6+OIY6AfP+260RktlLTWmLcWEZDzrBCc5dcSm7SjaQCbCjprn k2NSSPQjJy50L5qCLDT9CnZF3wye4TN6MAUkpTxKuFORVDnXAQnoIjFIp4kcS1t7/vmA Ye9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lrPG3Jo0g8IN2TUDjww3PLkkrQlh1VPumDr3dhWVCkk=; b=OTo5/2hgjgku6DmcOp+j96Ad9FqErIQQuXLHTRoTaXk1dWDwbqnKRTUpWkvISGb6fb oyh51n3UNAjx7iYRV6bmqWB5ZzXqhpejHLqZPnHaQ/5cZC35h29Z8/8OB2eneQxMvE3i JLMe0m3AjiYhWaMe7bvA43593pKk5P/ZBZm9daB1CQolhvqmjstMdOBmvLCF9VTyB6tA Fdr/0SgIe1mFZuAiWDngwiBilySxdbcfao1iw0ZwFXdPg7mEzV1RpkHbWac413ajsHMY Cu1VGAxBp7V0Ex4mank0xXZlqFD53GG1zdTtgQg3SIOGbn0g+7Gwk9XnNmHvfOiia+PM HaoA== X-Gm-Message-State: APjAAAUZ4QfG5/bV3K5zHsp1JLpgFoafHxCXMVlPDXRrO0LqfyOLw/HZ HKJ+cHRdE/Lq6CQmH5YV4PN6FQkpii8= X-Google-Smtp-Source: APXvYqxE60L7NqElsqqOOQetv4stCpru4Ah77SbcciphJ2rp20lCkcoA+xv/WPHXFPa78agvCxlCuA== X-Received: by 2002:a2e:9f0d:: with SMTP id u13mr25560786ljk.186.1564764002116; Fri, 02 Aug 2019 09:40:02 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id q6sm15378998lji.70.2019.08.02.09.40.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Aug 2019 09:40:01 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Fri, 2 Aug 2019 19:39:44 +0300 Message-Id: <1564763985-20312-6-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1564763985-20312-1-git-send-email-olekstysh@gmail.com> References: <1564763985-20312-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V2 5/6] iommu/arm: Introduce iommu_add_dt_device API 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: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Tyshchenko This patch adds new iommu_add_dt_device API for adding DT device to the IOMMU using generic IOMMU DT binding [1] and previously added "iommu_fwspec" support. New function parses the DT binding, prepares "dev->iommu_fwspec" with correct information and calls the IOMMU driver using "add_device" callback to register new DT device. The IOMMU driver's responsibility is to check whether "dev->iommu_fwspec" is initialized and mark that device as protected. The additional benefit here is to avoid to go through the whole DT multiple times in IOMMU driver trying to locate master devices which belong to each IOMMU device being probed. The upcoming IPMMU driver will have "add_device" callback implemented. I hope, this patch won't break SMMU driver's functionality, which doesn't have this callback implemented. [1] https://www.kernel.org/doc/Documentation/devicetree/bindings/iommu/iommu.txt Signed-off-by: Oleksandr Tyshchenko --- xen/arch/arm/domain_build.c | 12 ++++++++++ xen/drivers/passthrough/arm/iommu.c | 45 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/iommu.h | 3 +++ 3 files changed, 60 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d983677..d67f7d4 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1241,6 +1241,18 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, u64 addr, size; bool need_mapping = !dt_device_for_passthrough(dev); + if ( dt_parse_phandle(dev, "iommus", 0) ) + { + dt_dprintk("%s add to iommu\n", dt_node_full_name(dev)); + res = iommu_add_dt_device(dev); + if ( res ) + { + printk(XENLOG_ERR "Failed to add %s to the IOMMU\n", + dt_node_full_name(dev)); + return res; + } + } + nirq = dt_number_of_irq(dev); naddr = dt_number_of_address(dev); diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index 3195919..19516af 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -113,3 +113,48 @@ int arch_iommu_populate_page_table(struct domain *d) void __hwdom_init arch_iommu_hwdom_init(struct domain *d) { } + +int __init iommu_add_dt_device(struct dt_device_node *np) +{ + const struct iommu_ops *ops = iommu_get_ops(); + struct dt_phandle_args iommu_spec; + struct device *dev = dt_to_dev(np); + int rc = 1, index = 0; + + if ( !iommu_enabled || !ops || !ops->add_device ) + return 0; + + if ( dev_iommu_fwspec_get(dev) ) + return -EEXIST; + + /* According to the Documentation/devicetree/bindings/iommu/iommu.txt */ + while ( !dt_parse_phandle_with_args(np, "iommus", "#iommu-cells", + index, &iommu_spec) ) + { + if ( !dt_device_is_available(iommu_spec.np) ) + break; + + rc = iommu_fwspec_init(dev, &iommu_spec.np->dev); + if ( rc ) + break; + + rc = iommu_fwspec_add_ids(dev, iommu_spec.args, 1); + if ( rc ) + break; + + index++; + } + + /* + * Add DT device to the IOMMU if latter is present and available. + * The IOMMU driver's responsibility is to check whether dev->iommu_fwspec + * field is initialized and mark that device as protected. + */ + if ( !rc ) + rc = ops->add_device(0, dev); + + if ( rc < 0 ) + iommu_fwspec_free(dev); + + return rc < 0 ? rc : 0; +} diff --git a/xen/include/asm-arm/iommu.h b/xen/include/asm-arm/iommu.h index 1853bd9..06b07fa 100644 --- a/xen/include/asm-arm/iommu.h +++ b/xen/include/asm-arm/iommu.h @@ -28,6 +28,9 @@ struct arch_iommu const struct iommu_ops *iommu_get_ops(void); void iommu_set_ops(const struct iommu_ops *ops); +/* helper to add DT device to the IOMMU */ +int iommu_add_dt_device(struct dt_device_node *np); + /* mapping helpers */ int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn, unsigned int flags,