diff --git a/arch/arm/mach-msm/iommu_domains.c b/arch/arm/mach-msm/iommu_domains.c index 159d308a57d..261f8a88e60 100644 --- a/arch/arm/mach-msm/iommu_domains.c +++ b/arch/arm/mach-msm/iommu_domains.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -454,12 +455,11 @@ int msm_register_domain(struct msm_iova_layout *layout) if (data->domain_num < 0) goto free_pools; - data->domain = iommu_domain_alloc(bus, layout->domain_flags); + data->domain = iommu_domain_alloc(&platform_bus_type, + layout->domain_flags); if (!data->domain) goto free_domain_num; - msm_iommu_set_client_name(data->domain, layout->client_name); - add_domain(data); return data->domain_num; @@ -508,171 +508,6 @@ int msm_unregister_domain(struct iommu_domain *domain) } EXPORT_SYMBOL(msm_unregister_domain); -static int find_and_add_contexts(struct iommu_group *group, - const struct device_node *node, - unsigned int num_contexts) -{ - unsigned int i; - struct device *ctx; - const char *name; - struct device_node *ctx_node; - int ret_val = 0; - - for (i = 0; i < num_contexts; ++i) { - ctx_node = of_parse_phandle((struct device_node *) node, - "qcom,iommu-contexts", i); - if (!ctx_node) { - pr_err("Unable to parse phandle #%u\n", i); - ret_val = -EINVAL; - goto out; - } - if (of_property_read_string(ctx_node, "label", &name)) { - pr_err("Could not find label property\n"); - ret_val = -EINVAL; - goto out; - } - ctx = msm_iommu_get_ctx(name); - if (!ctx) { - pr_err("Unable to find context %s\n", name); - ret_val = -EINVAL; - goto out; - } - iommu_group_add_device(group, ctx); - } -out: - return ret_val; -} - -static int create_and_add_domain(struct iommu_group *group, - struct device_node const *node, - char const *name) -{ - unsigned int ret_val = 0; - unsigned int i, j; - struct msm_iova_layout l; - struct msm_iova_partition *part = 0; - struct iommu_domain *domain = 0; - unsigned int *addr_array; - unsigned int array_size; - int domain_no; - int secure_domain; - int l2_redirect; - - if (of_get_property(node, "qcom,virtual-addr-pool", &array_size)) { - l.npartitions = array_size / sizeof(unsigned int) / 2; - part = kmalloc( - sizeof(struct msm_iova_partition) * l.npartitions, - GFP_KERNEL); - if (!part) { - pr_err("%s: could not allocate space for partition", - __func__); - ret_val = -ENOMEM; - goto out; - } - addr_array = kmalloc(array_size, GFP_KERNEL); - if (!addr_array) { - pr_err("%s: could not allocate space for partition", - __func__); - ret_val = -ENOMEM; - goto free_mem; - } - - ret_val = of_property_read_u32_array(node, - "qcom,virtual-addr-pool", - addr_array, - array_size/sizeof(unsigned int)); - if (ret_val) { - ret_val = -EINVAL; - goto free_mem; - } - - for (i = 0, j = 0; j < l.npartitions * 2; i++, j += 2) { - part[i].start = addr_array[j]; - part[i].size = addr_array[j+1]; - } - } else { - l.npartitions = 1; - part = kmalloc( - sizeof(struct msm_iova_partition) * l.npartitions, - GFP_KERNEL); - if (!part) { - pr_err("%s: could not allocate space for partition", - __func__); - ret_val = -ENOMEM; - goto out; - } - part[0].start = 0x0; - part[0].size = 0xFFFFFFFF; - } - - l.client_name = name; - l.partitions = part; - - secure_domain = of_property_read_bool(node, "qcom,secure-domain"); - l.is_secure = (secure_domain) ? MSM_IOMMU_DOMAIN_SECURE : 0; - - l2_redirect = of_property_read_bool(node, "qcom,l2-redirect"); - l.domain_flags = (l2_redirect) ? MSM_IOMMU_DOMAIN_PT_CACHEABLE : 0; - - domain_no = msm_register_domain(&l); - if (domain_no >= 0) - domain = msm_get_iommu_domain(domain_no); - else - ret_val = domain_no; - - iommu_group_set_iommudata(group, domain, NULL); - -free_mem: - kfree(part); -out: - return ret_val; -} - -static int iommu_domain_parse_dt(const struct device_node *dt_node) -{ - struct device_node *node; - int sz; - unsigned int num_contexts; - int ret_val = 0; - struct iommu_group *group = 0; - const char *name; - - for_each_child_of_node(dt_node, node) { - group = iommu_group_alloc(); - if (IS_ERR(group)) { - ret_val = PTR_ERR(group); - goto out; - } - if (of_property_read_string(node, "label", &name)) { - ret_val = -EINVAL; - goto free_group; - } - iommu_group_set_name(group, name); - - if (!of_get_property(node, "qcom,iommu-contexts", &sz)) { - pr_err("Could not find qcom,iommu-contexts property\n"); - ret_val = -EINVAL; - goto free_group; - } - num_contexts = sz / sizeof(unsigned int); - - ret_val = find_and_add_contexts(group, node, num_contexts); - if (ret_val) { - ret_val = -EINVAL; - goto free_group; - } - ret_val = create_and_add_domain(group, node, name); - if (ret_val) { - ret_val = -EINVAL; - goto free_group; - } - } -free_group: - /* No iommu_group_free() function */ -out: - return ret_val; -} - static int iommu_domain_probe(struct platform_device *pdev) { struct iommu_domains_pdata *p = pdev->dev.platform_data;