diff options
author | Joerg Roedel <jroedel@suse.de> | 2017-03-31 09:12:31 -0400 |
---|---|---|
committer | Joerg Roedel <jroedel@suse.de> | 2017-04-03 07:17:02 -0400 |
commit | 6f66ea099fc2f31d31d6cd39f3b13b23bdeb6196 (patch) | |
tree | 488501c11cdd14c6eaa78bc7ffd01a5961728839 | |
parent | c02ed2e75ef4c74e41e421acb4ef1494671585e8 (diff) |
iommu/mediatek: Teach MTK-IOMMUv1 about 'struct iommu_device'
Make use of the iommu_device_register() interface.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
-rw-r--r-- | drivers/iommu/mtk_iommu_v1.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 19e010083408..a27ef570c328 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c | |||
@@ -431,9 +431,10 @@ err_release_mapping: | |||
431 | 431 | ||
432 | static int mtk_iommu_add_device(struct device *dev) | 432 | static int mtk_iommu_add_device(struct device *dev) |
433 | { | 433 | { |
434 | struct iommu_group *group; | ||
435 | struct of_phandle_args iommu_spec; | 434 | struct of_phandle_args iommu_spec; |
436 | struct of_phandle_iterator it; | 435 | struct of_phandle_iterator it; |
436 | struct mtk_iommu_data *data; | ||
437 | struct iommu_group *group; | ||
437 | int err; | 438 | int err; |
438 | 439 | ||
439 | of_for_each_phandle(&it, err, dev->of_node, "iommus", | 440 | of_for_each_phandle(&it, err, dev->of_node, "iommus", |
@@ -450,6 +451,9 @@ static int mtk_iommu_add_device(struct device *dev) | |||
450 | if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) | 451 | if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) |
451 | return -ENODEV; /* Not a iommu client device */ | 452 | return -ENODEV; /* Not a iommu client device */ |
452 | 453 | ||
454 | data = dev->iommu_fwspec->iommu_priv; | ||
455 | iommu_device_link(&data->iommu, dev); | ||
456 | |||
453 | group = iommu_group_get_for_dev(dev); | 457 | group = iommu_group_get_for_dev(dev); |
454 | if (IS_ERR(group)) | 458 | if (IS_ERR(group)) |
455 | return PTR_ERR(group); | 459 | return PTR_ERR(group); |
@@ -460,9 +464,14 @@ static int mtk_iommu_add_device(struct device *dev) | |||
460 | 464 | ||
461 | static void mtk_iommu_remove_device(struct device *dev) | 465 | static void mtk_iommu_remove_device(struct device *dev) |
462 | { | 466 | { |
467 | struct mtk_iommu_data *data; | ||
468 | |||
463 | if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) | 469 | if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) |
464 | return; | 470 | return; |
465 | 471 | ||
472 | data = dev->iommu_fwspec->iommu_priv; | ||
473 | iommu_device_unlink(&data->iommu, dev); | ||
474 | |||
466 | iommu_group_remove_device(dev); | 475 | iommu_group_remove_device(dev); |
467 | iommu_fwspec_free(dev); | 476 | iommu_fwspec_free(dev); |
468 | } | 477 | } |
@@ -627,6 +636,17 @@ static int mtk_iommu_probe(struct platform_device *pdev) | |||
627 | if (ret) | 636 | if (ret) |
628 | return ret; | 637 | return ret; |
629 | 638 | ||
639 | ret = iommu_device_sysfs_add(&data->iommu, &pdev->dev, NULL, | ||
640 | dev_name(&pdev->dev)); | ||
641 | if (ret) | ||
642 | return ret; | ||
643 | |||
644 | iommu_device_set_ops(&data->iommu, &mtk_iommu_ops); | ||
645 | |||
646 | ret = iommu_device_register(&data->iommu); | ||
647 | if (ret) | ||
648 | return ret; | ||
649 | |||
630 | if (!iommu_present(&platform_bus_type)) | 650 | if (!iommu_present(&platform_bus_type)) |
631 | bus_set_iommu(&platform_bus_type, &mtk_iommu_ops); | 651 | bus_set_iommu(&platform_bus_type, &mtk_iommu_ops); |
632 | 652 | ||
@@ -637,6 +657,9 @@ static int mtk_iommu_remove(struct platform_device *pdev) | |||
637 | { | 657 | { |
638 | struct mtk_iommu_data *data = platform_get_drvdata(pdev); | 658 | struct mtk_iommu_data *data = platform_get_drvdata(pdev); |
639 | 659 | ||
660 | iommu_device_sysfs_remove(&data->iommu); | ||
661 | iommu_device_unregister(&data->iommu); | ||
662 | |||
640 | if (iommu_present(&platform_bus_type)) | 663 | if (iommu_present(&platform_bus_type)) |
641 | bus_set_iommu(&platform_bus_type, NULL); | 664 | bus_set_iommu(&platform_bus_type, NULL); |
642 | 665 | ||