Re: [PATCH 3/3] iommu/tegra-smmu: Allow to group clients in same swgroup

2020-09-24 Thread Thierry Reding
On Fri, Sep 11, 2020 at 12:16:43AM -0700, Nicolin Chen wrote:
> There can be clients using the same swgroup in DT, for example i2c0
> and i2c1. The current driver will add them to separate IOMMU groups,
> though it has implemented device_group() callback which is to group
> devices using different swgroups like DC and DCB.
> 
> All clients having the same swgroup should be also added to the same
> IOMMU group so as to share an asid. Otherwise, the asid register may
> get overwritten every time a new device is attached.
> 
> Signed-off-by: Nicolin Chen 
> ---
>  drivers/iommu/tegra-smmu.c | 11 +++
>  1 file changed, 7 insertions(+), 4 deletions(-)

Makes sense:

Acked-by: Thierry Reding 


signature.asc
Description: PGP signature
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

[PATCH 3/3] iommu/tegra-smmu: Allow to group clients in same swgroup

2020-09-11 Thread Nicolin Chen
There can be clients using the same swgroup in DT, for example i2c0
and i2c1. The current driver will add them to separate IOMMU groups,
though it has implemented device_group() callback which is to group
devices using different swgroups like DC and DCB.

All clients having the same swgroup should be also added to the same
IOMMU group so as to share an asid. Otherwise, the asid register may
get overwritten every time a new device is attached.

Signed-off-by: Nicolin Chen 
---
 drivers/iommu/tegra-smmu.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 50b962b0647e..84fdee473873 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -23,6 +23,7 @@ struct tegra_smmu_group {
struct tegra_smmu *smmu;
const struct tegra_smmu_group_soc *soc;
struct iommu_group *group;
+   unsigned int swgroup;
 };
 
 struct tegra_smmu {
@@ -909,14 +910,14 @@ static struct iommu_group *tegra_smmu_group_get(struct 
tegra_smmu *smmu,
struct tegra_smmu_group *group;
struct iommu_group *grp;
 
+   /* Find group_soc associating with swgroup */
soc = tegra_smmu_find_group(smmu, swgroup);
-   if (!soc)
-   return NULL;
 
mutex_lock(>lock);
 
+   /* Find existing iommu_group associating with swgroup or group_soc */
list_for_each_entry(group, >groups, list)
-   if (group->soc == soc) {
+   if ((group->swgroup == swgroup) || (soc && group->soc == soc)) {
grp = iommu_group_ref_get(group->group);
mutex_unlock(>lock);
return grp;
@@ -929,6 +930,7 @@ static struct iommu_group *tegra_smmu_group_get(struct 
tegra_smmu *smmu,
}
 
INIT_LIST_HEAD(>list);
+   group->swgroup = swgroup;
group->smmu = smmu;
group->soc = soc;
 
@@ -940,7 +942,8 @@ static struct iommu_group *tegra_smmu_group_get(struct 
tegra_smmu *smmu,
}
 
iommu_group_set_iommudata(group->group, group, 
tegra_smmu_group_release);
-   iommu_group_set_name(group->group, soc->name);
+   if (soc)
+   iommu_group_set_name(group->group, soc->name);
list_add_tail(>list, >groups);
mutex_unlock(>lock);
 
-- 
2.17.1

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu