Skip to content

Commit

Permalink
iommu/renesas: Convert to probe/release_device() call-backs
Browse files Browse the repository at this point in the history
Convert the Renesas IOMMU driver 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-28-joro@8bytes.org
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Joerg Roedel committed May 5, 2020
1 parent b287ba7 commit 6580c8a
Showing 1 changed file with 20 additions and 40 deletions.
60 changes: 20 additions & 40 deletions drivers/iommu/ipmmu-vmsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,24 +805,8 @@ static int ipmmu_of_xlate(struct device *dev,
static int ipmmu_init_arm_mapping(struct device *dev)
{
struct ipmmu_vmsa_device *mmu = to_ipmmu(dev);
struct iommu_group *group;
int ret;

/* Create a device group and add the device to it. */
group = iommu_group_alloc();
if (IS_ERR(group)) {
dev_err(dev, "Failed to allocate IOMMU group\n");
return PTR_ERR(group);
}

ret = iommu_group_add_device(group, dev);
iommu_group_put(group);

if (ret < 0) {
dev_err(dev, "Failed to add device to IPMMU group\n");
return ret;
}

/*
* Create the ARM mapping, used by the ARM DMA mapping core to allocate
* VAs. This will allocate a corresponding IOMMU domain.
Expand Down Expand Up @@ -856,48 +840,39 @@ static int ipmmu_init_arm_mapping(struct device *dev)
return 0;

error:
iommu_group_remove_device(dev);
if (mmu->mapping)
arm_iommu_release_mapping(mmu->mapping);

return ret;
}

static int ipmmu_add_device(struct device *dev)
static struct iommu_device *ipmmu_probe_device(struct device *dev)
{
struct ipmmu_vmsa_device *mmu = to_ipmmu(dev);
struct iommu_group *group;
int ret;

/*
* Only let through devices that have been verified in xlate()
*/
if (!mmu)
return -ENODEV;
return ERR_PTR(-ENODEV);

if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) {
ret = ipmmu_init_arm_mapping(dev);
if (ret)
return ret;
} else {
group = iommu_group_get_for_dev(dev);
if (IS_ERR(group))
return PTR_ERR(group);
return &mmu->iommu;
}

iommu_group_put(group);
}
static void ipmmu_probe_finalize(struct device *dev)
{
int ret = 0;

iommu_device_link(&mmu->iommu, dev);
return 0;
if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA))
ret = ipmmu_init_arm_mapping(dev);

if (ret)
dev_err(dev, "Can't create IOMMU mapping - DMA-OPS will not work\n");
}

static void ipmmu_remove_device(struct device *dev)
static void ipmmu_release_device(struct device *dev)
{
struct ipmmu_vmsa_device *mmu = to_ipmmu(dev);

iommu_device_unlink(&mmu->iommu, dev);
arm_iommu_detach_device(dev);
iommu_group_remove_device(dev);
}

static struct iommu_group *ipmmu_find_group(struct device *dev)
Expand Down Expand Up @@ -925,9 +900,14 @@ static const struct iommu_ops ipmmu_ops = {
.flush_iotlb_all = ipmmu_flush_iotlb_all,
.iotlb_sync = ipmmu_iotlb_sync,
.iova_to_phys = ipmmu_iova_to_phys,
.add_device = ipmmu_add_device,
.remove_device = ipmmu_remove_device,
.probe_device = ipmmu_probe_device,
.release_device = ipmmu_release_device,
.probe_finalize = ipmmu_probe_finalize,
#if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA)
.device_group = generic_device_group,
#else
.device_group = ipmmu_find_group,
#endif
.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K,
.of_xlate = ipmmu_of_xlate,
};
Expand Down

0 comments on commit 6580c8a

Please sign in to comment.