Skip to content

Commit 57dbf81

Browse files
committed
iommu/mediatek-v1 Convert to probe/release_device() call-backs
Convert the Mediatek-v1 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 80e4592 commit 57dbf81

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

drivers/iommu/mtk_iommu_v1.c

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,12 @@ static int mtk_iommu_create_mapping(struct device *dev,
416416
return 0;
417417
}
418418

419-
static int mtk_iommu_add_device(struct device *dev)
419+
static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
420420
{
421421
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
422-
struct dma_iommu_mapping *mtk_mapping;
423422
struct of_phandle_args iommu_spec;
424423
struct of_phandle_iterator it;
425424
struct mtk_iommu_data *data;
426-
struct iommu_group *group;
427425
int err;
428426

429427
of_for_each_phandle(&it, err, dev->of_node, "iommus",
@@ -442,35 +440,28 @@ static int mtk_iommu_add_device(struct device *dev)
442440
}
443441

444442
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
445-
return -ENODEV; /* Not a iommu client device */
443+
return ERR_PTR(-ENODEV); /* Not a iommu client device */
446444

447-
/*
448-
* This is a short-term bodge because the ARM DMA code doesn't
449-
* understand multi-device groups, but we have to call into it
450-
* successfully (and not just rely on a normal IOMMU API attach
451-
* here) in order to set the correct DMA API ops on @dev.
452-
*/
453-
group = iommu_group_alloc();
454-
if (IS_ERR(group))
455-
return PTR_ERR(group);
445+
data = dev_iommu_priv_get(dev);
456446

457-
err = iommu_group_add_device(group, dev);
458-
iommu_group_put(group);
459-
if (err)
460-
return err;
447+
return &data->iommu;
448+
}
461449

462-
data = dev_iommu_priv_get(dev);
450+
static void mtk_iommu_probe_finalize(struct device *dev)
451+
{
452+
struct dma_iommu_mapping *mtk_mapping;
453+
struct mtk_iommu_data *data;
454+
int err;
455+
456+
data = dev_iommu_priv_get(dev);
463457
mtk_mapping = data->dev->archdata.iommu;
464-
err = arm_iommu_attach_device(dev, mtk_mapping);
465-
if (err) {
466-
iommu_group_remove_device(dev);
467-
return err;
468-
}
469458

470-
return iommu_device_link(&data->iommu, dev);
459+
err = arm_iommu_attach_device(dev, mtk_mapping);
460+
if (err)
461+
dev_err(dev, "Can't create IOMMU mapping - DMA-OPS will not work\n");
471462
}
472463

473-
static void mtk_iommu_remove_device(struct device *dev)
464+
static void mtk_iommu_release_device(struct device *dev)
474465
{
475466
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
476467
struct mtk_iommu_data *data;
@@ -479,9 +470,6 @@ static void mtk_iommu_remove_device(struct device *dev)
479470
return;
480471

481472
data = dev_iommu_priv_get(dev);
482-
iommu_device_unlink(&data->iommu, dev);
483-
484-
iommu_group_remove_device(dev);
485473
iommu_fwspec_free(dev);
486474
}
487475

@@ -534,8 +522,10 @@ static const struct iommu_ops mtk_iommu_ops = {
534522
.map = mtk_iommu_map,
535523
.unmap = mtk_iommu_unmap,
536524
.iova_to_phys = mtk_iommu_iova_to_phys,
537-
.add_device = mtk_iommu_add_device,
538-
.remove_device = mtk_iommu_remove_device,
525+
.probe_device = mtk_iommu_probe_device,
526+
.probe_finalize = mtk_iommu_probe_finalize,
527+
.release_device = mtk_iommu_release_device,
528+
.device_group = generic_device_group,
539529
.pgsize_bitmap = ~0UL << MT2701_IOMMU_PAGE_SHIFT,
540530
};
541531

0 commit comments

Comments
 (0)