From patchwork Thu Jan 21 12:36:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 367839 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp532860jam; Thu, 21 Jan 2021 04:42:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqNoRA7WfdKSEz640k0XOyrc5wxmCrgR0zZ54PnXG9LCkRCPsWpYqH7dOIUUYco4CIe5cy X-Received: by 2002:a17:906:2f07:: with SMTP id v7mr9019939eji.343.1611232974894; Thu, 21 Jan 2021 04:42:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611232974; cv=none; d=google.com; s=arc-20160816; b=X2trXY+uoQpeOdwP8XVwdCaUPVzPUgj7DoewqKAu14r3KnjBbISkIDiKDhnA5W5QFe gVxrQILIvooZup1PfBc83HEZvuIBsMfJbrFQ8Et0PbkF4frXR6brTfYgpdUxSiyJoesn IUinZUH4TeSzH5icNRNV6Mg5E0D4O7uY1K06kxB6NazUJ621x0qitbiyC3EmafKDR5Er A6Y99cJVMeZYqDrhn2bxzuYieRwPb5g2Oh33CdtLfdycKjajcavztQ56e9qkn7Du/xXB cinOF7dOK4B4mv6jzHpgPL1qW53TyIf4uur1UkuufE+79RTTSL6+MJsw1mgmYjZl9Sl2 MJZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2eRhKsVau0r7rYJc5kg9wODttGekaxkRDREYSkG2V3g=; b=uSlerSB1tAjtzH/8h11dq83xG9nFjO/va/t7kNRiGDyO0l/gfnv7vfHdGCkg79GLm3 jonQRNJuNL/me1ZTKYmni1KIapk648cOVl/kS0c/c7Wk0vWvFR2qf3gUEwv348Q+ZtcJ kPTjFMmJzlMRx4Tqj/xkQl7eguSmeoplJAqDl8rC/r1m/DfBIEL2bSwTUxNRhOPupv5W iXozJbcf5wYFzRXdPNFYoQ8l7rcLOCyjFqpz7rX+g96fDttTtWke5NIMfHe62iq2jJcx +fuk/pwmZZEG5qdoWVPNiTeDm0obrIfAbmZw2kVlQAOuCdh9RPTgbGho83KdtVcu+OVO LDKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QuUMjiy5; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r7si2072058edv.345.2021.01.21.04.42.54; Thu, 21 Jan 2021 04:42:54 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QuUMjiy5; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731359AbhAUMlg (ORCPT + 6 others); Thu, 21 Jan 2021 07:41:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731366AbhAUMlD (ORCPT ); Thu, 21 Jan 2021 07:41:03 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0DECC061796 for ; Thu, 21 Jan 2021 04:39:38 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id c124so1320519wma.5 for ; Thu, 21 Jan 2021 04:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2eRhKsVau0r7rYJc5kg9wODttGekaxkRDREYSkG2V3g=; b=QuUMjiy5ho1cz1ta5kVsxHS6pccVZgC9l6zL1qsFa7+VqjNpuf/uQnkpICVteQGTmp 5LfYliJDrpBW/gPgpB7ezB5xGV1T8K0b2SaRShfvi4yMh0bYjCt/utdFGEstkQVoNjiA eFM8A9hStx44vAI2iPyPAZRme9cDQULk4hw1TIurC9IApmOLPwdVgoG+9t85+7OtvPu/ k//FGUbAqr9XsDSOm8HxrfdVW2FadDrap3RhH4vIsdF4h1+6UmL/+ThjrnrGApVO3mss VFwc3rD61MYEuRJPv+T1m/isVhd6pid/9m4XbVK/WijzMQ62V4m7JSmViDa9OzIQA9hl UX6g== 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:mime-version:content-transfer-encoding; bh=2eRhKsVau0r7rYJc5kg9wODttGekaxkRDREYSkG2V3g=; b=GERMl6Ra7+RRU59lNPFOb/cn8zGF9vD5F10s02AS4i/9dx92bOaNNYq6AUdeVNPtvN zut5yC+3wLVjDm11tApQCtBKFYeuk3c6fHJgTpeB5iLlyLiG2L5KqlDKOTEla2rvM9nQ rDBVCsoXiRTkTA3YSdli+64q1GJJrG60UGFdoXwC2dngbyHuRBbJ2GyHV4YZeDABYqhG /887EcdD+RazZuNZ/SYEqK0Qa57F87aQdDbpCbQC4ZevarR9hen9qvUOKYLlNLFsqM6H ayJYkOKduxXdfaEcMizjYqe+DIIrjLnUoTtpCkYheFoPlsIEDcdeKT+OyDl+dGwWR/Q9 +RLQ== X-Gm-Message-State: AOAM530x4ZCIxZ+WJaXLazDxSxkwXB2YgDKA3e0WLkm5qTT2/W//zVi0 FA5TY0rgeOMuV+ANa2RQhwEK+w== X-Received: by 2002:a05:600c:1986:: with SMTP id t6mr8703507wmq.93.1611232777425; Thu, 21 Jan 2021 04:39:37 -0800 (PST) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id p18sm7979248wmc.31.2021.01.21.04.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 04:39:36 -0800 (PST) From: Jean-Philippe Brucker To: joro@8bytes.org, will@kernel.org Cc: lorenzo.pieralisi@arm.com, robh+dt@kernel.org, guohanjun@huawei.com, sudeep.holla@arm.com, rjw@rjwysocki.net, lenb@kernel.org, robin.murphy@arm.com, Jonathan.Cameron@huawei.com, eric.auger@redhat.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-accelerators@lists.ozlabs.org, baolu.lu@linux.intel.com, jacob.jun.pan@linux.intel.com, kevin.tian@intel.com, vdumpa@nvidia.com, zhangfei.gao@linaro.org, shameerali.kolothum.thodi@huawei.com, vivek.gautam@arm.com, Jean-Philippe Brucker , Arnd Bergmann , Greg Kroah-Hartman , Zhou Wang Subject: [PATCH v10 05/10] uacce: Enable IOMMU_DEV_FEAT_IOPF Date: Thu, 21 Jan 2021 13:36:19 +0100 Message-Id: <20210121123623.2060416-6-jean-philippe@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210121123623.2060416-1-jean-philippe@linaro.org> References: <20210121123623.2060416-1-jean-philippe@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The IOPF (I/O Page Fault) feature is now enabled independently from the SVA feature, because some IOPF implementations are device-specific and do not require IOMMU support for PCIe PRI or Arm SMMU stall. Enable IOPF unconditionally when enabling SVA for now. In the future, if a device driver implementing a uacce interface doesn't need IOPF support, it will need to tell the uacce module, for example with a new flag. Acked-by: Zhangfei Gao Signed-off-by: Jean-Philippe Brucker --- Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: Zhangfei Gao Cc: Zhou Wang --- drivers/misc/uacce/uacce.c | 39 +++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) -- 2.30.0 diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index d07af4edfcac..6db7a98486ec 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -385,6 +385,33 @@ static void uacce_release(struct device *dev) kfree(uacce); } +static unsigned int uacce_enable_sva(struct device *parent, unsigned int flags) +{ + if (!(flags & UACCE_DEV_SVA)) + return flags; + + flags &= ~UACCE_DEV_SVA; + + if (iommu_dev_enable_feature(parent, IOMMU_DEV_FEAT_IOPF)) + return flags; + + if (iommu_dev_enable_feature(parent, IOMMU_DEV_FEAT_SVA)) { + iommu_dev_disable_feature(parent, IOMMU_DEV_FEAT_IOPF); + return flags; + } + + return flags | UACCE_DEV_SVA; +} + +static void uacce_disable_sva(struct uacce_device *uacce) +{ + if (!(uacce->flags & UACCE_DEV_SVA)) + return; + + iommu_dev_disable_feature(uacce->parent, IOMMU_DEV_FEAT_SVA); + iommu_dev_disable_feature(uacce->parent, IOMMU_DEV_FEAT_IOPF); +} + /** * uacce_alloc() - alloc an accelerator * @parent: pointer of uacce parent device @@ -404,11 +431,7 @@ struct uacce_device *uacce_alloc(struct device *parent, if (!uacce) return ERR_PTR(-ENOMEM); - if (flags & UACCE_DEV_SVA) { - ret = iommu_dev_enable_feature(parent, IOMMU_DEV_FEAT_SVA); - if (ret) - flags &= ~UACCE_DEV_SVA; - } + flags = uacce_enable_sva(parent, flags); uacce->parent = parent; uacce->flags = flags; @@ -432,8 +455,7 @@ struct uacce_device *uacce_alloc(struct device *parent, return uacce; err_with_uacce: - if (flags & UACCE_DEV_SVA) - iommu_dev_disable_feature(uacce->parent, IOMMU_DEV_FEAT_SVA); + uacce_disable_sva(uacce); kfree(uacce); return ERR_PTR(ret); } @@ -487,8 +509,7 @@ void uacce_remove(struct uacce_device *uacce) mutex_unlock(&uacce->queues_lock); /* disable sva now since no opened queues */ - if (uacce->flags & UACCE_DEV_SVA) - iommu_dev_disable_feature(uacce->parent, IOMMU_DEV_FEAT_SVA); + uacce_disable_sva(uacce); if (uacce->cdev) cdev_device_del(uacce->cdev, &uacce->dev);