iommu: exynos: add callback for initializing devices from device tree
authorMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 23 Jan 2015 15:51:28 +0000 (16:51 +0100)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Mon, 13 Apr 2015 10:44:14 +0000 (12:44 +0200)
This patch adds implementation of of_xlate callback, which prepares
masters device for attaching to IOMMU. This callback is called during
creating devices from device tree.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
drivers/iommu/exynos-iommu.c

index 3197035756328b0a8908172d127d39e1bf62d9f7..a361cc89bb84a776f84da803c7b8939e6d46cb34 100644 (file)
@@ -1077,6 +1077,33 @@ static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *iommu_domain,
        return phys;
 }
 
+static int exynos_iommu_of_xlate(struct device *dev,
+                                struct of_phandle_args *spec)
+{
+       struct exynos_iommu_owner *owner = dev->archdata.iommu;
+       struct platform_device *sysmmu = of_find_device_by_node(spec->np);
+       struct sysmmu_drvdata *data;
+
+       if (!sysmmu)
+               return -ENODEV;
+
+       data = platform_get_drvdata(sysmmu);
+       if (!data)
+               return -ENODEV;
+
+       if (!owner) {
+               owner = kzalloc(sizeof(*owner), GFP_KERNEL);
+               if (!owner)
+                       return -ENOMEM;
+
+               INIT_LIST_HEAD(&owner->clients);
+               dev->archdata.iommu = owner;
+       }
+
+       list_add_tail(&data->owner_node, &owner->clients);
+       return 0;
+}
+
 static struct iommu_ops exynos_iommu_ops = {
        .domain_init = exynos_iommu_domain_init,
        .domain_destroy = exynos_iommu_domain_destroy,
@@ -1087,6 +1114,7 @@ static struct iommu_ops exynos_iommu_ops = {
        .map_sg = default_iommu_map_sg,
        .iova_to_phys = exynos_iommu_iova_to_phys,
        .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE,
+       .of_xlate = exynos_iommu_of_xlate,
 };
 
 static int init_done;