Skip to content

Commit 6580c8a

Browse files
committed
iommu/renesas: Convert to probe/release_device() call-backs
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent b287ba7 commit 6580c8a

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

drivers/iommu/ipmmu-vmsa.c

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -805,24 +805,8 @@ static int ipmmu_of_xlate(struct device *dev,
805805
static int ipmmu_init_arm_mapping(struct device *dev)
806806
{
807807
struct ipmmu_vmsa_device *mmu = to_ipmmu(dev);
808-
struct iommu_group *group;
809808
int ret;
810809

811-
/* Create a device group and add the device to it. */
812-
group = iommu_group_alloc();
813-
if (IS_ERR(group)) {
814-
dev_err(dev, "Failed to allocate IOMMU group\n");
815-
return PTR_ERR(group);
816-
}
817-
818-
ret = iommu_group_add_device(group, dev);
819-
iommu_group_put(group);
820-
821-
if (ret < 0) {
822-
dev_err(dev, "Failed to add device to IPMMU group\n");
823-
return ret;
824-
}
825-
826810
/*
827811
* Create the ARM mapping, used by the ARM DMA mapping core to allocate
828812
* VAs. This will allocate a corresponding IOMMU domain.
@@ -856,48 +840,39 @@ static int ipmmu_init_arm_mapping(struct device *dev)
856840
return 0;
857841

858842
error:
859-
iommu_group_remove_device(dev);
860843
if (mmu->mapping)
861844
arm_iommu_release_mapping(mmu->mapping);
862845

863846
return ret;
864847
}
865848

866-
static int ipmmu_add_device(struct device *dev)
849+
static struct iommu_device *ipmmu_probe_device(struct device *dev)
867850
{
868851
struct ipmmu_vmsa_device *mmu = to_ipmmu(dev);
869-
struct iommu_group *group;
870-
int ret;
871852

872853
/*
873854
* Only let through devices that have been verified in xlate()
874855
*/
875856
if (!mmu)
876-
return -ENODEV;
857+
return ERR_PTR(-ENODEV);
877858

878-
if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA)) {
879-
ret = ipmmu_init_arm_mapping(dev);
880-
if (ret)
881-
return ret;
882-
} else {
883-
group = iommu_group_get_for_dev(dev);
884-
if (IS_ERR(group))
885-
return PTR_ERR(group);
859+
return &mmu->iommu;
860+
}
886861

887-
iommu_group_put(group);
888-
}
862+
static void ipmmu_probe_finalize(struct device *dev)
863+
{
864+
int ret = 0;
889865

890-
iommu_device_link(&mmu->iommu, dev);
891-
return 0;
866+
if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA))
867+
ret = ipmmu_init_arm_mapping(dev);
868+
869+
if (ret)
870+
dev_err(dev, "Can't create IOMMU mapping - DMA-OPS will not work\n");
892871
}
893872

894-
static void ipmmu_remove_device(struct device *dev)
873+
static void ipmmu_release_device(struct device *dev)
895874
{
896-
struct ipmmu_vmsa_device *mmu = to_ipmmu(dev);
897-
898-
iommu_device_unlink(&mmu->iommu, dev);
899875
arm_iommu_detach_device(dev);
900-
iommu_group_remove_device(dev);
901876
}
902877

903878
static struct iommu_group *ipmmu_find_group(struct device *dev)
@@ -925,9 +900,14 @@ static const struct iommu_ops ipmmu_ops = {
925900
.flush_iotlb_all = ipmmu_flush_iotlb_all,
926901
.iotlb_sync = ipmmu_iotlb_sync,
927902
.iova_to_phys = ipmmu_iova_to_phys,
928-
.add_device = ipmmu_add_device,
929-
.remove_device = ipmmu_remove_device,
903+
.probe_device = ipmmu_probe_device,
904+
.release_device = ipmmu_release_device,
905+
.probe_finalize = ipmmu_probe_finalize,
906+
#if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA)
907+
.device_group = generic_device_group,
908+
#else
930909
.device_group = ipmmu_find_group,
910+
#endif
931911
.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K,
932912
.of_xlate = ipmmu_of_xlate,
933913
};

0 commit comments

Comments
 (0)