From patchwork Wed Jan 27 15:43:18 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: 371565 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp386190jam; Wed, 27 Jan 2021 07:48:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZ2IvSVT/5w5ruXsX3RnrXTxw5AqT7sye36VHMx8mVvnLTr8lzQRpFZEi/aTioKSMGCZOh X-Received: by 2002:a05:6402:1c8b:: with SMTP id cy11mr9949770edb.256.1611762482513; Wed, 27 Jan 2021 07:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611762482; cv=none; d=google.com; s=arc-20160816; b=H4v8bJcw9UmPXipnnNql0eVnuCm0iLEfiY6HnqqMXlMjehpVWfkrbbQB9fhdQIXKU8 oFlDvGdfmZ/EBp24QsAmGbHCY0imXX/pwKYK0ofzjcmRLcFi1B9HmtOEmJ3yIkzQ/VCX ooI89mmfXl7RDHJ6Ckn0ij6cFxusarb+A6O1Dd8pr+mCBAfQs0Az60I9uJ09q4kcLmZM wuwExEtGe1LMJqoKMloYh+alCfiATepULfp/9ySvefgLKK9AVnnVWiCR86Zie8pJDGmc 2xW/emxh0v7nF7t2bocFQF5inu3gVylj8HlNocaOFFkNxI8sls+x184o3qq6voklLdL8 Eo3g== 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=HA2Upai17zp88bLXxFSVJINfRnd5MRj2IEKHoTGmCb87sKpAwx8pYRJXpcxSDTPOLZ wLAQJ8LrhLNaWghZgde/wg66Wh8iTHhdI8g7g9zTZ9DYl2ewDi+DqpMOzFpf4E1qU9W5 6bL+kPuM0zXRCfpHS5Eu0tPPL0dqxEntQstSznWLUkSArh2CSjl4RqJybTWCIgdNSOtp ZNCQeyfRzgtZLvpCau7Wii1sbFqY1GLZOB4whrphoPXrR6Urpi64qWUquFneId303tBS US1tnlKIuf6HkUN3oceQoladF7gBPo455iG/SJNCCPTWosISxWjozQKgLQiwa2aCLLzc CWPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ivODR+o+; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-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 cy17si1201994edb.193.2021.01.27.07.48.02; Wed, 27 Jan 2021 07:48:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-acpi-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=ivODR+o+; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-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 S236459AbhA0Prg (ORCPT + 4 others); Wed, 27 Jan 2021 10:47:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236411AbhA0Ppl (ORCPT ); Wed, 27 Jan 2021 10:45:41 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E898C0617A9 for ; Wed, 27 Jan 2021 07:44:41 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id s24so3550912wmj.0 for ; Wed, 27 Jan 2021 07:44:41 -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=ivODR+o+zeC+VLJ0NgPRRPEDqKLo115ma74DNu8zGnxMHACyPpvmyq2NbKEY54zWcC HMm/wagqjHGCTD9o5sOyQaYdwXrhGcQkH2bd8KUAVmSLDxtP1uQgJJQRingKBA0YhTVP sWQ+mMRICXpCezAP6Oj2gsHkGf+PQTmlM6VqnZ2A0kBbV37ha72LnnyjtE1Y1DSOhWUn uSlXLg2b3WTL1E3LYGyJUyJOQ3ycX5g0wj/1R/jq2nm0TPNsCHwArjYP5pnIHZKPQdek rkX5+FHD4bTJn/ZGAgi+VVGF9SZRHo5GHcqKmqn+22Vc1eUWA9hrfnlUvtNucqx/emx/ 3qUw== 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=ajuReMqu7H+xcrV41q12nQSvrv+Vivixk65P/4xebVhXh4Nw45I3+oIaDL4ashihl3 9QHseo4Q9pjytQtNVMs4Kc8JFC4fEXdRaNPaOysxGh4pKm44UEKZD+Fq5DXFP1WB5d0U kT5sfdL4wzhm36ghT0hTdrvVcI7X2X28LtV2QxHWT/Depb2+h9X5E6XZCJGKAwGgE9rM YcJCT5PfcqXdmK7gLDRsKZvd7rGBD001PbFvIFlViezYvh29ylONT27qSt74+nDA38RL 3JhJmRiNPeDjrSeRz/Nadu5Ub7+qB/6KlJYw+kIi8nmJ9OmgY6wb1UyrWs/LpNJ+V5P7 5QZQ== X-Gm-Message-State: AOAM530ylROp8VHlVkxw5mNRPzO7M42pVjuCgwjOdZDx9cSMManpuhG5 WMP/7lNDod3XujQTj5CQWdLD2Q== X-Received: by 2002:a1c:7e4e:: with SMTP id z75mr4860472wmc.168.1611762280149; Wed, 27 Jan 2021 07:44:40 -0800 (PST) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id r13sm3046921wmh.9.2021.01.27.07.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 07:44:39 -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 v12 05/10] uacce: Enable IOMMU_DEV_FEAT_IOPF Date: Wed, 27 Jan 2021 16:43:18 +0100 Message-Id: <20210127154322.3959196-6-jean-philippe@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210127154322.3959196-1-jean-philippe@linaro.org> References: <20210127154322.3959196-1-jean-philippe@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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);