Skip to content

Commit

Permalink
iommu/mediatek: Teach MTK-IOMMUv1 about 'struct iommu_device'
Browse files Browse the repository at this point in the history
Make use of the iommu_device_register() interface.

Signed-off-by: Joerg Roedel <[email protected]>
  • Loading branch information
joergroedel committed Apr 3, 2017
1 parent c02ed2e commit 6f66ea0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion drivers/iommu/mtk_iommu_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,10 @@ static int mtk_iommu_create_mapping(struct device *dev,

static int mtk_iommu_add_device(struct device *dev)
{
struct iommu_group *group;
struct of_phandle_args iommu_spec;
struct of_phandle_iterator it;
struct mtk_iommu_data *data;
struct iommu_group *group;
int err;

of_for_each_phandle(&it, err, dev->of_node, "iommus",
Expand All @@ -450,6 +451,9 @@ static int mtk_iommu_add_device(struct device *dev)
if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
return -ENODEV; /* Not a iommu client device */

data = dev->iommu_fwspec->iommu_priv;
iommu_device_link(&data->iommu, dev);

group = iommu_group_get_for_dev(dev);
if (IS_ERR(group))
return PTR_ERR(group);
Expand All @@ -460,9 +464,14 @@ static int mtk_iommu_add_device(struct device *dev)

static void mtk_iommu_remove_device(struct device *dev)
{
struct mtk_iommu_data *data;

if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
return;

data = dev->iommu_fwspec->iommu_priv;
iommu_device_unlink(&data->iommu, dev);

iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
Expand Down Expand Up @@ -627,6 +636,17 @@ static int mtk_iommu_probe(struct platform_device *pdev)
if (ret)
return ret;

ret = iommu_device_sysfs_add(&data->iommu, &pdev->dev, NULL,
dev_name(&pdev->dev));
if (ret)
return ret;

iommu_device_set_ops(&data->iommu, &mtk_iommu_ops);

ret = iommu_device_register(&data->iommu);
if (ret)
return ret;

if (!iommu_present(&platform_bus_type))
bus_set_iommu(&platform_bus_type, &mtk_iommu_ops);

Expand All @@ -637,6 +657,9 @@ static int mtk_iommu_remove(struct platform_device *pdev)
{
struct mtk_iommu_data *data = platform_get_drvdata(pdev);

iommu_device_sysfs_remove(&data->iommu);
iommu_device_unregister(&data->iommu);

if (iommu_present(&platform_bus_type))
bus_set_iommu(&platform_bus_type, NULL);

Expand Down

0 comments on commit 6f66ea0

Please sign in to comment.