Пример #1
0
static int get_device_address(struct smem_client *smem_client,
		struct ion_handle *hndl, unsigned long align,
		dma_addr_t *iova, unsigned long *buffer_size,
		u32 flags, enum hal_buffer buffer_type)
{
	int rc = 0;
	int domain, partition;
	struct ion_client *clnt = NULL;

	if (!iova || !buffer_size || !hndl || !smem_client) {
		dprintk(VIDC_ERR, "Invalid params: %pK, %pK, %pK, %pK\n",
				smem_client, hndl, iova, buffer_size);
		return -EINVAL;
	}

	clnt = smem_client->clnt;
	if (!clnt) {
		dprintk(VIDC_ERR, "Invalid client\n");
		return -EINVAL;
	}

	rc = msm_smem_get_domain_partition(smem_client, flags, buffer_type,
			&domain, &partition);
	if (rc) {
		dprintk(VIDC_ERR, "Failed to get domain and partition: %d\n",
				rc);
		goto mem_domain_get_failed;
	}

	if (flags & SMEM_SECURE) {
		rc = msm_ion_secure_buffer(clnt, hndl,
			get_tz_usage(smem_client, buffer_type), 0);
		if (rc) {
			dprintk(VIDC_ERR, "Failed to secure memory\n");
			goto mem_domain_get_failed;
		}
	}
	if (is_iommu_present(smem_client->res)) {
		dprintk(VIDC_DBG,
				"Calling ion_map_iommu - domain: %d, partition: %d\n",
				domain, partition);
		rc = ion_map_iommu(clnt, hndl, domain, partition, align,
				0, iova, buffer_size, 0, 0);
	} else {
		dprintk(VIDC_DBG, "Using physical memory address\n");
		rc = ion_phys(clnt, hndl, iova, (size_t *)buffer_size);
	}
	if (rc) {
		dprintk(VIDC_ERR, "ion memory map failed - %d\n", rc);
		goto mem_map_failed;
	}

	return 0;
mem_map_failed:
	if (flags & SMEM_SECURE)
		msm_ion_unsecure_buffer(clnt, hndl);
mem_domain_get_failed:
	return rc;
}
static int mdp_mmap(struct v4l2_subdev *sd, void *arg)
{
	int rc = 0, align = 0;
	struct mem_region_map *mmap = arg;
	struct mem_region *mregion;
	int domain = -1;
	struct mdp_instance *inst = NULL;

	if (!mmap || !mmap->mregion || !mmap->cookie) {
		WFD_MSG_ERR("Invalid argument\n");
		return -EINVAL;
	}

	inst = mmap->cookie;
	mregion = mmap->mregion;
	align = inst->secure ? SZ_1M : SZ_4K;
	if (mregion->size % align != 0) {
		WFD_MSG_ERR("Memregion not aligned to %d\n", align);
		return -EINVAL;
	}

	msm_fb_writeback_iommu_ref(inst->mdp, true);
	if (inst->secure) {
		rc = msm_ion_secure_buffer(mmap->ion_client,
			mregion->ion_handle, VIDEO_PIXEL, 0);
		if (rc) {
			WFD_MSG_ERR("Failed to secure input buffer\n");
			goto secure_fail;
		}
	}

	domain = msm_fb_get_iommu_domain(inst->mdp,
			inst->secure ? MDP_IOMMU_DOMAIN_CP :
					MDP_IOMMU_DOMAIN_NS);

	rc = ion_map_iommu(mmap->ion_client, mregion->ion_handle,
			domain, 0, align, 0,
			(unsigned long *)&mregion->paddr,
			(unsigned long *)&mregion->size,
			0, 0);
	if (rc) {
		WFD_MSG_ERR("Failed to map into %ssecure domain: %d\n",
				!inst->secure ? "non" : "", rc);
		goto iommu_fail;
	}
	msm_fb_writeback_iommu_ref(inst->mdp, false);

	return 0;
iommu_fail:
	if (inst->secure)
		msm_ion_unsecure_buffer(mmap->ion_client, mregion->ion_handle);
secure_fail:
	msm_fb_writeback_iommu_ref(inst->mdp, false);

	return rc;
}
Пример #3
0
int mdss_mdp_get_img(struct msmfb_data *img, struct mdss_mdp_img_data *data)
{
	struct file *file;
	int ret = -EINVAL;
	int fb_num;
	unsigned long *start, *len;
	struct ion_client *iclient = mdss_get_ionclient();

	start = (unsigned long *) &data->addr;
	len = (unsigned long *) &data->len;
	data->flags |= img->flags;
	data->p_need = 0;

	if (img->flags & MDP_BLIT_SRC_GEM) {
		data->srcp_file = NULL;
		ret = kgsl_gem_obj_addr(img->memory_id, (int) img->priv,
					start, len);
	} else if (img->flags & MDP_MEMORY_ID_TYPE_FB) {
		file = fget_light(img->memory_id, &data->p_need);
		if (file == NULL) {
			pr_err("invalid framebuffer file (%d)\n",
					img->memory_id);
			return -EINVAL;
		}
		data->srcp_file = file;

		if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
			fb_num = MINOR(file->f_dentry->d_inode->i_rdev);
			ret = mdss_fb_get_phys_info(start, len, fb_num);
			if (ret)
				pr_err("mdss_fb_get_phys_info() failed\n");
		} else {
			pr_err("invalid FB_MAJOR\n");
			ret = -1;
		}
	} else if (iclient) {
		data->srcp_ihdl = ion_import_dma_buf(iclient, img->memory_id);
		if (IS_ERR_OR_NULL(data->srcp_ihdl)) {
			pr_err("error on ion_import_fd\n");
			ret = PTR_ERR(data->srcp_ihdl);
			data->srcp_ihdl = NULL;
			return ret;
		}

		if (is_mdss_iommu_attached()) {
			int domain;
			if (data->flags & MDP_SECURE_OVERLAY_SESSION) {
				domain = MDSS_IOMMU_DOMAIN_SECURE;

				mdss_mdp_secure_vote(1);
				ret = msm_ion_secure_buffer(iclient,
					data->srcp_ihdl, 0x2, 0);
				if (IS_ERR_VALUE(ret)) {
					ion_free(iclient, data->srcp_ihdl);
					pr_err("failed to secure handle (%d)\n",
						ret);
					return ret;
				}
			} else {
				domain = MDSS_IOMMU_DOMAIN_UNSECURE;
			}

			ret = ion_map_iommu(iclient, data->srcp_ihdl,
					    mdss_get_iommu_domain(domain),
					    0, SZ_4K, 0, start, len, 0, 0);
		} else {
			ret = ion_phys(iclient, data->srcp_ihdl, start,
				       (size_t *) len);
		}

		if (IS_ERR_VALUE(ret)) {
			ion_free(iclient, data->srcp_ihdl);
			pr_err("failed to map ion handle (%d)\n", ret);
			return ret;
		}
	}

	if (!*start) {
		pr_err("start address is zero!\n");
		return -ENOMEM;
	}

	if (!ret && (img->offset < data->len)) {
		data->addr += img->offset;
		data->len -= img->offset;

		pr_debug("mem=%d ihdl=%p buf=0x%x len=0x%x\n", img->memory_id,
			 data->srcp_ihdl, data->addr, data->len);
	} else {
		return -EINVAL;
	}

	return ret;
}