Skip to content

Commit b16c017

Browse files
committed
iommu/mediatek: Make use of iommu_device_register interface
Register individual Mediatek IOMMUs to the iommu core and add sysfs entries. Cc: Matthias Brugger <matthias.bgg@gmail.com> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-mediatek@lists.infradead.org Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 42df43b commit b16c017

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,15 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain,
360360

361361
static int mtk_iommu_add_device(struct device *dev)
362362
{
363+
struct mtk_iommu_data *data;
363364
struct iommu_group *group;
364365

365366
if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
366367
return -ENODEV; /* Not a iommu client device */
367368

369+
data = dev->iommu_fwspec->iommu_priv;
370+
iommu_device_link(&data->iommu, dev);
371+
368372
group = iommu_group_get_for_dev(dev);
369373
if (IS_ERR(group))
370374
return PTR_ERR(group);
@@ -375,9 +379,14 @@ static int mtk_iommu_add_device(struct device *dev)
375379

376380
static void mtk_iommu_remove_device(struct device *dev)
377381
{
382+
struct mtk_iommu_data *data;
383+
378384
if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
379385
return;
380386

387+
data = dev->iommu_fwspec->iommu_priv;
388+
iommu_device_unlink(&data->iommu, dev);
389+
381390
iommu_group_remove_device(dev);
382391
iommu_fwspec_free(dev);
383392
}
@@ -497,6 +506,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
497506
struct mtk_iommu_data *data;
498507
struct device *dev = &pdev->dev;
499508
struct resource *res;
509+
resource_size_t ioaddr;
500510
struct component_match *match = NULL;
501511
void *protect;
502512
int i, larb_nr, ret;
@@ -519,6 +529,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
519529
data->base = devm_ioremap_resource(dev, res);
520530
if (IS_ERR(data->base))
521531
return PTR_ERR(data->base);
532+
ioaddr = res->start;
522533

523534
data->irq = platform_get_irq(pdev, 0);
524535
if (data->irq < 0)
@@ -567,6 +578,18 @@ static int mtk_iommu_probe(struct platform_device *pdev)
567578
if (ret)
568579
return ret;
569580

581+
ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
582+
"mtk-iommu.%pa", &ioaddr);
583+
if (ret)
584+
return ret;
585+
586+
iommu_device_set_ops(&data->iommu, &mtk_iommu_ops);
587+
iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode);
588+
589+
ret = iommu_device_register(&data->iommu);
590+
if (ret)
591+
return ret;
592+
570593
if (!iommu_present(&platform_bus_type))
571594
bus_set_iommu(&platform_bus_type, &mtk_iommu_ops);
572595

@@ -577,6 +600,9 @@ static int mtk_iommu_remove(struct platform_device *pdev)
577600
{
578601
struct mtk_iommu_data *data = platform_get_drvdata(pdev);
579602

603+
iommu_device_sysfs_remove(&data->iommu);
604+
iommu_device_unregister(&data->iommu);
605+
580606
if (iommu_present(&platform_bus_type))
581607
bus_set_iommu(&platform_bus_type, NULL);
582608

drivers/iommu/mtk_iommu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ struct mtk_iommu_data {
4747
struct iommu_group *m4u_group;
4848
struct mtk_smi_iommu smi_imu; /* SMI larb iommu info */
4949
bool enable_4GB;
50+
51+
struct iommu_device iommu;
5052
};
5153

5254
static inline int compare_of(struct device *dev, void *data)

0 commit comments

Comments
 (0)