Эх сурвалжийг харах

msm: camera: smmu: Unmap secure buffers in secure camera use case

Dettach and unmap DMA buffers obtained previously from DMA attach
and mappings respectively.

CRs-Fixed: 3014632
Change-Id: If8f8ebe9fc270f2ba39a9a42ab7c7bfb0f79c4eb
Signed-off-by: Shadul Shaikh <[email protected]>
Shadul Shaikh 3 жил өмнө
parent
commit
083480979f

+ 22 - 2
drivers/cam_smmu/cam_smmu_api.c

@@ -220,6 +220,8 @@ struct cam_dma_buff_info {
 
 
 struct cam_sec_buff_info {
 struct cam_sec_buff_info {
 	struct dma_buf *buf;
 	struct dma_buf *buf;
+	struct dma_buf_attachment *attach;
+	struct sg_table *table;
 	enum dma_data_direction dir;
 	enum dma_data_direction dir;
 	int ref_count;
 	int ref_count;
 	dma_addr_t paddr;
 	dma_addr_t paddr;
@@ -3012,6 +3014,8 @@ static int cam_smmu_map_stage2_buffer_and_add_to_list(int idx, int ion_fd,
 	mapping_info->dir = dma_dir;
 	mapping_info->dir = dma_dir;
 	mapping_info->ref_count = 1;
 	mapping_info->ref_count = 1;
 	mapping_info->buf = dmabuf;
 	mapping_info->buf = dmabuf;
+	mapping_info->attach = attach;
+	mapping_info->table = table;
 
 
 	CAM_DBG(CAM_SMMU, "idx=%d, ion_fd=%d, i_ino=%lu, dev=%pOFfp, paddr=0x%llx, len=%zu",
 	CAM_DBG(CAM_SMMU, "idx=%d, ion_fd=%d, i_ino=%lu, dev=%pOFfp, paddr=0x%llx, len=%zu",
 		idx, ion_fd, mapping_info->i_ino,
 		idx, ion_fd, mapping_info->i_ino,
@@ -3111,11 +3115,27 @@ static int cam_smmu_secure_unmap_buf_and_remove_from_list(
 		struct cam_sec_buff_info *mapping_info,
 		struct cam_sec_buff_info *mapping_info,
 		int idx)
 		int idx)
 {
 {
-	if (!mapping_info) {
-		CAM_ERR(CAM_SMMU, "Error: List doesn't exist");
+	if ((!mapping_info->buf) || (!mapping_info->table) ||
+		(!mapping_info->attach)) {
+		CAM_ERR(CAM_SMMU, "Error: Invalid params dev = %pK, table = %pK",
+			(void *)iommu_cb_set.cb_info[idx].dev,
+			(void *)mapping_info->table);
+		CAM_ERR(CAM_SMMU, "Error:dma_buf = %pK, attach = %pK\n",
+			(void *)mapping_info->buf,
+			(void *)mapping_info->attach);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
+
+	/* skip cache operations */
+	mapping_info->attach->dma_map_attrs |= DMA_ATTR_SKIP_CPU_SYNC;
+
+	/* iommu buffer clean up */
+	dma_buf_unmap_attachment(mapping_info->attach,
+		mapping_info->table, mapping_info->dir);
+	dma_buf_detach(mapping_info->buf, mapping_info->attach);
 	dma_buf_put(mapping_info->buf);
 	dma_buf_put(mapping_info->buf);
+	mapping_info->buf = NULL;
+
 	list_del_init(&mapping_info->list);
 	list_del_init(&mapping_info->list);
 
 
 	CAM_DBG(CAM_SMMU, "unmap fd: %d, i_ino : %lu, idx : %d",
 	CAM_DBG(CAM_SMMU, "unmap fd: %d, i_ino : %lu, idx : %d",