Commit b16c0170 authored by Joerg Roedel's avatar Joerg Roedel

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: default avatarJoerg Roedel <jroedel@suse.de>
parent 42df43b3
...@@ -360,11 +360,15 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain, ...@@ -360,11 +360,15 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain,
static int mtk_iommu_add_device(struct device *dev) static int mtk_iommu_add_device(struct device *dev)
{ {
struct mtk_iommu_data *data;
struct iommu_group *group; struct iommu_group *group;
if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
return -ENODEV; /* Not a iommu client device */ 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); group = iommu_group_get_for_dev(dev);
if (IS_ERR(group)) if (IS_ERR(group))
return PTR_ERR(group); return PTR_ERR(group);
...@@ -375,9 +379,14 @@ static int mtk_iommu_add_device(struct device *dev) ...@@ -375,9 +379,14 @@ static int mtk_iommu_add_device(struct device *dev)
static void mtk_iommu_remove_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) if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
return; return;
data = dev->iommu_fwspec->iommu_priv;
iommu_device_unlink(&data->iommu, dev);
iommu_group_remove_device(dev); iommu_group_remove_device(dev);
iommu_fwspec_free(dev); iommu_fwspec_free(dev);
} }
...@@ -497,6 +506,7 @@ static int mtk_iommu_probe(struct platform_device *pdev) ...@@ -497,6 +506,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
struct mtk_iommu_data *data; struct mtk_iommu_data *data;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct resource *res; struct resource *res;
resource_size_t ioaddr;
struct component_match *match = NULL; struct component_match *match = NULL;
void *protect; void *protect;
int i, larb_nr, ret; int i, larb_nr, ret;
...@@ -519,6 +529,7 @@ static int mtk_iommu_probe(struct platform_device *pdev) ...@@ -519,6 +529,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
data->base = devm_ioremap_resource(dev, res); data->base = devm_ioremap_resource(dev, res);
if (IS_ERR(data->base)) if (IS_ERR(data->base))
return PTR_ERR(data->base); return PTR_ERR(data->base);
ioaddr = res->start;
data->irq = platform_get_irq(pdev, 0); data->irq = platform_get_irq(pdev, 0);
if (data->irq < 0) if (data->irq < 0)
...@@ -567,6 +578,18 @@ static int mtk_iommu_probe(struct platform_device *pdev) ...@@ -567,6 +578,18 @@ static int mtk_iommu_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
"mtk-iommu.%pa", &ioaddr);
if (ret)
return ret;
iommu_device_set_ops(&data->iommu, &mtk_iommu_ops);
iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode);
ret = iommu_device_register(&data->iommu);
if (ret)
return ret;
if (!iommu_present(&platform_bus_type)) if (!iommu_present(&platform_bus_type))
bus_set_iommu(&platform_bus_type, &mtk_iommu_ops); bus_set_iommu(&platform_bus_type, &mtk_iommu_ops);
...@@ -577,6 +600,9 @@ static int mtk_iommu_remove(struct platform_device *pdev) ...@@ -577,6 +600,9 @@ static int mtk_iommu_remove(struct platform_device *pdev)
{ {
struct mtk_iommu_data *data = platform_get_drvdata(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)) if (iommu_present(&platform_bus_type))
bus_set_iommu(&platform_bus_type, NULL); bus_set_iommu(&platform_bus_type, NULL);
......
...@@ -47,6 +47,8 @@ struct mtk_iommu_data { ...@@ -47,6 +47,8 @@ struct mtk_iommu_data {
struct iommu_group *m4u_group; struct iommu_group *m4u_group;
struct mtk_smi_iommu smi_imu; /* SMI larb iommu info */ struct mtk_smi_iommu smi_imu; /* SMI larb iommu info */
bool enable_4GB; bool enable_4GB;
struct iommu_device iommu;
}; };
static inline int compare_of(struct device *dev, void *data) static inline int compare_of(struct device *dev, void *data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment