Skip to content

Commit

Permalink
iommu/tegra: Convert to probe/release_device() call-backs
Browse files Browse the repository at this point in the history
Convert the Tegra IOMMU drivers to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Link: https://lore.kernel.org/r/20200429133712.31431-27-joro@8bytes.org
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Joerg Roedel committed May 5, 2020
1 parent d826044 commit b287ba7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
24 changes: 6 additions & 18 deletions drivers/iommu/tegra-gart.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,28 +243,16 @@ static bool gart_iommu_capable(enum iommu_cap cap)
return false;
}

static int gart_iommu_add_device(struct device *dev)
static struct iommu_device *gart_iommu_probe_device(struct device *dev)
{
struct iommu_group *group;

if (!dev_iommu_fwspec_get(dev))
return -ENODEV;

group = iommu_group_get_for_dev(dev);
if (IS_ERR(group))
return PTR_ERR(group);

iommu_group_put(group);
return ERR_PTR(-ENODEV);

iommu_device_link(&gart_handle->iommu, dev);

return 0;
return &gart_handle->iommu;
}

static void gart_iommu_remove_device(struct device *dev)
static void gart_iommu_release_device(struct device *dev)
{
iommu_group_remove_device(dev);
iommu_device_unlink(&gart_handle->iommu, dev);
}

static int gart_iommu_of_xlate(struct device *dev,
Expand All @@ -290,8 +278,8 @@ static const struct iommu_ops gart_iommu_ops = {
.domain_free = gart_iommu_domain_free,
.attach_dev = gart_iommu_attach_dev,
.detach_dev = gart_iommu_detach_dev,
.add_device = gart_iommu_add_device,
.remove_device = gart_iommu_remove_device,
.probe_device = gart_iommu_probe_device,
.release_device = gart_iommu_release_device,
.device_group = generic_device_group,
.map = gart_iommu_map,
.unmap = gart_iommu_unmap,
Expand Down
31 changes: 8 additions & 23 deletions drivers/iommu/tegra-smmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,10 @@ static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev,
return 0;
}

static int tegra_smmu_add_device(struct device *dev)
static struct iommu_device *tegra_smmu_probe_device(struct device *dev)
{
struct device_node *np = dev->of_node;
struct tegra_smmu *smmu = NULL;
struct iommu_group *group;
struct of_phandle_args args;
unsigned int index = 0;
int err;
Expand All @@ -774,7 +773,7 @@ static int tegra_smmu_add_device(struct device *dev)
of_node_put(args.np);

if (err < 0)
return err;
return ERR_PTR(err);

/*
* Only a single IOMMU master interface is currently
Expand All @@ -783,8 +782,6 @@ static int tegra_smmu_add_device(struct device *dev)
*/
dev->archdata.iommu = smmu;

iommu_device_link(&smmu->iommu, dev);

break;
}

Expand All @@ -793,26 +790,14 @@ static int tegra_smmu_add_device(struct device *dev)
}

if (!smmu)
return -ENODEV;

group = iommu_group_get_for_dev(dev);
if (IS_ERR(group))
return PTR_ERR(group);

iommu_group_put(group);
return ERR_PTR(-ENODEV);

return 0;
return &smmu->iommu;
}

static void tegra_smmu_remove_device(struct device *dev)
static void tegra_smmu_release_device(struct device *dev)
{
struct tegra_smmu *smmu = dev->archdata.iommu;

if (smmu)
iommu_device_unlink(&smmu->iommu, dev);

dev->archdata.iommu = NULL;
iommu_group_remove_device(dev);
}

static const struct tegra_smmu_group_soc *
Expand Down Expand Up @@ -895,8 +880,8 @@ static const struct iommu_ops tegra_smmu_ops = {
.domain_free = tegra_smmu_domain_free,
.attach_dev = tegra_smmu_attach_dev,
.detach_dev = tegra_smmu_detach_dev,
.add_device = tegra_smmu_add_device,
.remove_device = tegra_smmu_remove_device,
.probe_device = tegra_smmu_probe_device,
.release_device = tegra_smmu_release_device,
.device_group = tegra_smmu_device_group,
.map = tegra_smmu_map,
.unmap = tegra_smmu_unmap,
Expand Down Expand Up @@ -1015,7 +1000,7 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
* value. However the IOMMU registration process will attempt to add
* all devices to the IOMMU when bus_set_iommu() is called. In order
* not to rely on global variables to track the IOMMU instance, we
* set it here so that it can be looked up from the .add_device()
* set it here so that it can be looked up from the .probe_device()
* callback via the IOMMU device's .drvdata field.
*/
mc->smmu = smmu;
Expand Down

0 comments on commit b287ba7

Please sign in to comment.