Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp267030pxb; Mon, 13 Sep 2021 18:52:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+IIK/93YpvJB5paPOUtCGHcSUgVadrznMHAU0VJ8/hejGFhOj7cvHDgb9+PPX4SgspmgR X-Received: by 2002:a17:906:7302:: with SMTP id di2mr16783933ejc.409.1631584375031; Mon, 13 Sep 2021 18:52:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631584375; cv=none; d=google.com; s=arc-20160816; b=UysJ388ZcXw+G9i+wQxRI93yT0NPpGGun3/dvPev0DILOZk9L8wzkWxUAOgzHvRGXh QIhFWjwGLcZ/jOpU5rpLlRJVO033QBYAvfE0o9eOoxu8T2oDhU757dysL3Kt/khX2BrD uvhIOnfFgiV7fYJ/fAGiufcvHdnXHuhSKN7Q4BMOY01kp25IRhDptbC0UuKzlzi/XLNO EJn8tXtEOHDogkbXWDMX1+u8mNlbUvYBGe05rSjK2GivhQUwUn30PNWiS+kAFldmYGF7 dBjhLoiYxNocLhjWRbyMcq8rZESpQl/2nHR6NETAu8Sa30sfd/eAbUDnopxHb/O3/3H6 ybAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=FAqoKbYCswJVkOTch12PwlqXExdb3kYI3vk6OlVyx9g=; b=hlI/TWnpBZyaocKGuk8rN44eM2qSv9naTsPz5Z4kLrfFiWh9EmUvYO6p8A76RMsk5M Wi3pCSthZLCmffMc7dSIYlZWqASJWYFh7PZO0fcNTZFTn7MPgi3hev+etl6Omw06gn8c PXUpgyM+M+VVz++pef0NNPvC+xiodK1XqxX5T6tqAmLLY265XRguQNOiF9JTshEXGpWj RkUXhCiNSG13Xy3tPUtiBVmykuz9T6lHbzJAAYBJLITZ0PC88/p/hPmYGdV01B1fI+A/ I2S+m+ltGg0Qy9W0pujHHNNSuGPmqm4OwJHTuWyrMCgWz1T/7zf107YvKjNz/VPj7lAY K6wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gYBEGwhE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j22si8951948edt.286.2021.09.13.18.52.31; Mon, 13 Sep 2021 18:52:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@gmail.com header.s=20210112 header.b=gYBEGwhE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236708AbhINBtC (ORCPT + 99 others); Mon, 13 Sep 2021 21:49:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234225AbhINBsy (ORCPT ); Mon, 13 Sep 2021 21:48:54 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF9CAC061574; Mon, 13 Sep 2021 18:47:37 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id n13-20020a17090a4e0d00b0017946980d8dso877107pjh.5; Mon, 13 Sep 2021 18:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FAqoKbYCswJVkOTch12PwlqXExdb3kYI3vk6OlVyx9g=; b=gYBEGwhEWqK0u1Ir4IzJ5vtfdG6eyqheL1fWG7eZhyXjzYaRJuljD+x6xfVdsAcLy9 w1nwv5KBwT13wTATYjeDWdrEnty6t1LzqTQXBPrWabwZOod9P3Zx4QnSSoWWez3kT4HN +dJXJ29R34Xr+qFuYOe5UxbVHWgqOOBrEaCb/qaACvNjZr3kHba+g3RsJPeiwdmRRV7r I7hJL8cz8fUphVmj6yqnXQNBMZC83hWrMxZXwLbwW1O13DUcTHt2T0ktb5Eh5CYEcl9T kVRkqNc0cFsKMq0UuUPUAEWzbfBhEX7y7/cCTaNExkd6lSjBGEjNmWsuq8BztNmvvtYm d6qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FAqoKbYCswJVkOTch12PwlqXExdb3kYI3vk6OlVyx9g=; b=qYES/XDg0GJJn2xQeFErFhdsxCmku9RiePmZuQHXbtFkba1QzHPGmABshgCA2Ti//P +ZHC8D9sesQ5vvUoYO39sqDJr4d7KOIvfBUPIXgk7dGvZ/vuR8mxCSS3+4F28MrZ6Wu9 EXwme5IMjgtFXwerfv6Xpy7c05MWTx88ApxzKuSVVN3vVt2XLp0KHa3ZnVSTytEEXfLQ 9bA8AwDlF/CAr4E2Hg6D9fXiuXMPds9NQ/r1YiU9PyZ6wKwxq7N4UTzOPKsFHHBQuzy/ MMW659k2VPu0MJrnmAjcRq1XTqvUFDiUakwVUkKNyl4n2Re2TulNutc1yT7JqPGXyn3L brZA== X-Gm-Message-State: AOAM531v0nebCk9rJrOvUyjEL4Ge1o86LCJ54+EF0qZZDNYd0L+KX/+4 bRJDCYv/dNQuv/9/L2x7RxCU4lwzikQ4qw== X-Received: by 2002:a17:902:a3cf:b0:13a:70c6:f911 with SMTP id q15-20020a170902a3cf00b0013a70c6f911mr12895659plb.42.1631584057258; Mon, 13 Sep 2021 18:47:37 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id z11sm8270101pfr.157.2021.09.13.18.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 18:47:36 -0700 (PDT) From: Nicolin Chen To: thierry.reding@gmail.com, joro@8bytes.org, will@kernel.org Cc: vdumpa@nvidia.com, jonathanh@nvidia.com, linux-tegra@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, digetx@gmail.com Subject: [PATCH v6 5/6] iommu/tegra-smmu: Attach as pointer to tegra_smmu_group Date: Mon, 13 Sep 2021 18:38:57 -0700 Message-Id: <20210914013858.31192-6-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210914013858.31192-1-nicoleotsuka@gmail.com> References: <20210914013858.31192-1-nicoleotsuka@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This could ease driver to access corresponding as pointer when having tegra_smmu_group pointer only, which can help new mappings debugfs nodes. Also moving tegra_smmu_find_group_soc() upward, for using it in new tegra_smmu_attach_as(); and it's better to have all tegra_smmu_find_* functions together. Signed-off-by: Nicolin Chen --- drivers/iommu/tegra-smmu.c | 94 +++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 8fd4985ac91e..68c34a4a0ecc 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -24,6 +24,7 @@ struct tegra_smmu_group { struct tegra_smmu *smmu; const struct tegra_smmu_group_soc *group_soc; const struct tegra_smmu_swgroup *swgrp; + struct tegra_smmu_as *as; struct iommu_group *grp; }; @@ -349,6 +350,19 @@ tegra_smmu_find_swgrp(struct tegra_smmu *smmu, unsigned int swgroup) return swgrp; } +static const struct tegra_smmu_group_soc * +tegra_smmu_find_group_soc(struct tegra_smmu *smmu, unsigned int swgroup) +{ + unsigned int i, j; + + for (i = 0; i < smmu->soc->num_groups; i++) + for (j = 0; j < smmu->soc->groups[i].num_swgroups; j++) + if (smmu->soc->groups[i].swgroups[j] == swgroup) + return &smmu->soc->groups[i]; + + return NULL; +} + static void tegra_smmu_enable(struct tegra_smmu *smmu, unsigned int swgroup, unsigned int asid) { @@ -482,6 +496,57 @@ static void tegra_smmu_as_unprepare(struct tegra_smmu *smmu, mutex_unlock(&smmu->lock); } +static void tegra_smmu_attach_as(struct tegra_smmu *smmu, + struct tegra_smmu_as *as, + unsigned int swgroup) +{ + const struct tegra_smmu_swgroup *swgrp; + struct tegra_smmu_group *group; + + /* Find swgrp according to the swgroup id */ + swgrp = tegra_smmu_find_swgrp(smmu, swgroup); + if (!swgrp) + return; + + mutex_lock(&smmu->lock); + + list_for_each_entry(group, &smmu->groups, list) { + if (group->swgrp != swgrp) + continue; + if (group->as) + dev_warn(smmu->dev, + "overwriting group->as for swgroup: %s\n", swgrp->name); + group->as = as; + break; + } + + mutex_unlock(&smmu->lock); +} + +static void tegra_smmu_detach_as(struct tegra_smmu *smmu, + unsigned int swgroup) +{ + const struct tegra_smmu_swgroup *swgrp; + struct tegra_smmu_group *group; + struct dentry *d; + + /* Find swgrp according to the swgroup id */ + swgrp = tegra_smmu_find_swgrp(smmu, swgroup); + if (!swgrp) + return; + + mutex_lock(&smmu->lock); + + list_for_each_entry(group, &smmu->groups, list) { + if (group->swgrp != swgrp) + continue; + group->as = NULL; + break; + } + + mutex_unlock(&smmu->lock); +} + static int tegra_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { @@ -495,11 +560,15 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain, return -ENOENT; for (index = 0; index < fwspec->num_ids; index++) { + unsigned int swgroup = fwspec->ids[index]; + err = tegra_smmu_as_prepare(smmu, as); if (err) goto disable; - tegra_smmu_enable(smmu, fwspec->ids[index], as->id); + tegra_smmu_attach_as(smmu, as, swgroup); + + tegra_smmu_enable(smmu, swgroup, as->id); } if (index == 0) @@ -509,7 +578,10 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain, disable: while (index--) { - tegra_smmu_disable(smmu, fwspec->ids[index], as->id); + unsigned int swgroup = fwspec->ids[index]; + + tegra_smmu_disable(smmu, swgroup, as->id); + tegra_smmu_detach_as(smmu, swgroup); tegra_smmu_as_unprepare(smmu, as); } @@ -527,7 +599,10 @@ static void tegra_smmu_detach_dev(struct iommu_domain *domain, struct device *de return; for (index = 0; index < fwspec->num_ids; index++) { - tegra_smmu_disable(smmu, fwspec->ids[index], as->id); + unsigned int swgroup = fwspec->ids[index]; + + tegra_smmu_disable(smmu, swgroup, as->id); + tegra_smmu_detach_as(smmu, swgroup); tegra_smmu_as_unprepare(smmu, as); } } @@ -869,19 +944,6 @@ static struct iommu_device *tegra_smmu_probe_device(struct device *dev) static void tegra_smmu_release_device(struct device *dev) {} -static const struct tegra_smmu_group_soc * -tegra_smmu_find_group_soc(struct tegra_smmu *smmu, unsigned int swgroup) -{ - unsigned int i, j; - - for (i = 0; i < smmu->soc->num_groups; i++) - for (j = 0; j < smmu->soc->groups[i].num_swgroups; j++) - if (smmu->soc->groups[i].swgroups[j] == swgroup) - return &smmu->soc->groups[i]; - - return NULL; -} - static void tegra_smmu_group_release(void *iommu_data) { struct tegra_smmu_group *group = iommu_data; -- 2.17.1