فهرست منبع

msm: camera: core: v780 enhanced memory addresses

Added support for v780 enhanced memory address handling

CRs-Fixed: 2948659
Change-Id: I46ed16ad70103553a18cc69d762c6d93fc9fd8d9
Signed-off-by: Karthik Jayakumar <[email protected]>
Karthik Jayakumar 4 سال پیش
والد
کامیت
0d00f4feee

+ 1 - 1
drivers/cam_cdm/cam_cdm_hw_core.c

@@ -1054,7 +1054,7 @@ int cam_hw_cdm_submit_bl(struct cam_hw_info *cdm_hw,
 			rc = cam_mem_get_io_buf(
 				cdm_cmd->cmd[i].bl_addr.mem_handle,
 				core->iommu_hdl.non_secure, &hw_vaddr_ptr,
-				&len);
+				&len, NULL);
 		} else if (req->data->type == CAM_CDM_BL_CMD_TYPE_HW_IOVA) {
 			if (!cdm_cmd->cmd[i].bl_addr.hw_iova) {
 				CAM_ERR(CAM_CDM,

+ 3 - 9
drivers/cam_cre/cam_cre_hw_mgr/cam_cre_hw_mgr.c

@@ -165,12 +165,12 @@ static int cam_cre_mgr_process_cmd_io_buf_req(struct cam_cre_hw_mgr *hw_mgr,
 					rc = cam_mem_get_io_buf(
 						io_cfg_ptr[j].mem_handle[k],
 						hw_mgr->iommu_sec_hdl,
-						&iova_addr, &len);
+						&iova_addr, &len, NULL);
 				else
 					rc = cam_mem_get_io_buf(
 						io_cfg_ptr[j].mem_handle[k],
 						hw_mgr->iommu_hdl,
-						&iova_addr, &len);
+						&iova_addr, &len, NULL);
 
 				if (rc) {
 					CAM_ERR(CAM_CRE, "get buf failed: %d",
@@ -2098,7 +2098,7 @@ static void cam_cre_mgr_print_io_bufs(struct cam_packet *packet,
 				io_cfg[i].mem_handle[j]) ? sec_mmu_hdl :
 				iommu_hdl;
 			rc = cam_mem_get_io_buf(io_cfg[i].mem_handle[j],
-				mmu_hdl, &iova_addr, &src_buf_size);
+				mmu_hdl, &iova_addr, &src_buf_size, NULL);
 			if (rc < 0) {
 				CAM_ERR(CAM_UTIL,
 					"get src buf address fail rc %d mem %x",
@@ -2106,12 +2106,6 @@ static void cam_cre_mgr_print_io_bufs(struct cam_packet *packet,
 				continue;
 			}
 
-			if ((iova_addr & 0xFFFFFFFF) != iova_addr) {
-				CAM_ERR(CAM_CRE, "Invalid mapped address");
-				rc = -EINVAL;
-				continue;
-			}
-
 			CAM_INFO(CAM_CRE,
 				"pln %d dir %d w %d h %d s %u sh %u sz %zu addr 0x%llx off 0x%x memh %x",
 				j, io_cfg[i].direction,

+ 2 - 2
drivers/cam_cust/cam_custom_hw_mgr/cam_custom_hw_mgr.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/slab.h>
@@ -1195,7 +1195,7 @@ static int cam_custom_add_io_buffers(
 					io_cfg[i].mem_handle[plane_id],
 					iommu_hdl,
 					&prepare_hw_data->io_addr[plane_id],
-					&size);
+					&size, NULL);
 				if (rc) {
 					CAM_ERR(CAM_CUSTOM,
 						"No io addr for plane: %d",

+ 1 - 1
drivers/cam_fd/fd_hw_mgr/cam_fd_hw_mgr.c

@@ -596,7 +596,7 @@ static int cam_fd_mgr_util_prepare_io_buf_info(int32_t iommu_hdl,
 			if (need_io_map) {
 				rc = cam_mem_get_io_buf(
 					io_cfg[i].mem_handle[plane],
-					iommu_hdl, &io_addr[plane], &size);
+					iommu_hdl, &io_addr[plane], &size, NULL);
 				if (rc) {
 					CAM_ERR(CAM_FD,
 						"Failed to get io buf %u %u %u %d",

+ 5 - 10
drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c

@@ -4479,7 +4479,7 @@ static int cam_icp_mgr_process_cmd_desc(struct cam_icp_hw_mgr *hw_mgr,
 	for (i = 0; i < packet->num_cmd_buf; i++, num_cmd_buf++) {
 		if (cmd_desc[i].type == CAM_CMD_BUF_FW) {
 			rc = cam_mem_get_io_buf(cmd_desc[i].mem_handle,
-				hw_mgr->iommu_hdl, &addr, &len);
+				hw_mgr->iommu_hdl, &addr, &len, NULL);
 			if (rc) {
 				CAM_ERR(CAM_ICP, "get cmd buf failed %x",
 					hw_mgr->iommu_hdl);
@@ -4626,7 +4626,7 @@ static int cam_icp_process_stream_settings(
 	for (i = 0; i < cmd_mem_regions->num_regions; i++) {
 		rc = cam_mem_get_io_buf(
 			cmd_mem_regions->map_info_array[i].mem_handle,
-			icp_hw_mgr.iommu_hdl, &iova, &len);
+			icp_hw_mgr.iommu_hdl, &iova, &len, NULL);
 		if (rc) {
 			CAM_ERR(CAM_ICP,
 				"Failed to get cmd region iova for handle %u",
@@ -4853,7 +4853,7 @@ static int cam_icp_packet_generic_blob_handler(void *user_data,
 		rc = cam_mem_get_io_buf(
 			ctx_data->icp_dev_io_info.io_config_cmd_handle,
 			icp_hw_mgr.iommu_hdl,
-			blob->io_buf_addr, &io_buf_size);
+			blob->io_buf_addr, &io_buf_size, NULL);
 		if (rc)
 			CAM_ERR(CAM_ICP, "Failed in blob update");
 		else
@@ -5043,17 +5043,12 @@ static void cam_icp_mgr_print_io_bufs(struct cam_packet *packet,
 				io_cfg[i].mem_handle[j]) ? sec_mmu_hdl :
 				iommu_hdl;
 			rc = cam_mem_get_io_buf(io_cfg[i].mem_handle[j],
-				mmu_hdl, &iova_addr, &src_buf_size);
+				mmu_hdl, &iova_addr, &src_buf_size, NULL);
 			if (rc < 0) {
 				CAM_ERR(CAM_UTIL,
 					"get src buf address fail rc %d", rc);
 				continue;
 			}
-			if ((iova_addr & 0xFFFFFFFF) != iova_addr) {
-				CAM_ERR(CAM_ICP, "Invalid mapped address");
-				rc = -EINVAL;
-				continue;
-			}
 
 			CAM_INFO(CAM_ICP,
 				"pln %d dir %d w %d h %d s %u sh %u sz %zu addr 0x%llx off 0x%x memh %x",
@@ -5886,7 +5881,7 @@ static int cam_icp_mgr_acquire_hw(void *hw_mgr_priv, void *acquire_hw_args)
 	rc = cam_mem_get_io_buf(
 		icp_dev_acquire_info->io_config_cmd_handle,
 		hw_mgr->iommu_hdl,
-		&io_buf_addr, &io_buf_size);
+		&io_buf_addr, &io_buf_size, NULL);
 	if (rc) {
 		CAM_ERR(CAM_ICP, "unable to get src buf info from io desc");
 		goto get_io_buf_failed;

+ 7 - 4
drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c

@@ -7060,7 +7060,7 @@ static int cam_isp_blob_sfe_scratch_buf_update(
 		}
 
 		rc = cam_mem_get_io_buf(buffer_info->mem_handle,
-			mmu_hdl, &io_addr, &size);
+			mmu_hdl, &io_addr, &size, NULL);
 		if (rc) {
 			CAM_ERR(CAM_ISP,
 				"no scratch buf addr for res: 0x%x",
@@ -8846,7 +8846,7 @@ static int cam_ife_mgr_util_insert_frame_header(
 			hw_mgr->mgr_common.img_iommu_hdl;
 
 	rc = cam_mem_get_io_buf(kmd_buf->handle, mmu_hdl,
-		&iova_addr, &len);
+		&iova_addr, &len, NULL);
 	if (rc) {
 		CAM_ERR(CAM_ISP,
 			"Failed to get io addr for handle = %d for mmu_hdl = %u",
@@ -10083,7 +10083,7 @@ static void cam_ife_mgr_print_io_bufs(struct cam_ife_hw_mgr  *hw_mgr,
 				io_cfg[i].mem_handle[j]) ? sec_mmu_hdl :
 				iommu_hdl;
 			rc = cam_mem_get_io_buf(io_cfg[i].mem_handle[j],
-				mmu_hdl, &iova_addr, &src_buf_size);
+				mmu_hdl, &iova_addr, &src_buf_size, NULL);
 			if (rc < 0) {
 				CAM_ERR(CAM_ISP,
 					"get src buf address fail mem_handle 0x%x",
@@ -11534,6 +11534,7 @@ static int cam_ife_hw_mgr_check_rdi_scratch_buf_done(
 {
 	int rc = 0;
 	struct cam_sfe_scratch_buf_info *buf_info;
+	uint32_t cmp_addr = 0;
 
 	if (!scratch_cfg->config_done) {
 		CAM_DBG(CAM_ISP, "No scratch config for ctx: %u", ctx_index);
@@ -11545,7 +11546,9 @@ static int cam_ife_hw_mgr_check_rdi_scratch_buf_done(
 	case CAM_ISP_SFE_OUT_RES_RDI_1:
 	case CAM_ISP_SFE_OUT_RES_RDI_2:
 		buf_info = &scratch_cfg->buf_info[res_id - CAM_ISP_SFE_OUT_RES_BASE];
-		if (buf_info->io_addr == last_consumed_addr) {
+		cmp_addr = cam_smmu_is_expanded_memory() ?
+			CAM_36BIT_INTF_GET_IOVA_BASE(buf_info->io_addr) : buf_info->io_addr;
+		if (cmp_addr == last_consumed_addr) {
 			CAM_DBG(CAM_ISP, "SFE RDI%u buf done for scratch - skip ctx notify",
 				(res_id - CAM_ISP_SFE_OUT_RES_BASE));
 			rc = -EAGAIN;

+ 2 - 2
drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c

@@ -2876,7 +2876,7 @@ static int cam_tfe_mgr_config_hw(void *hw_mgr_priv,
 			cdm_cmd->cmd[i].bl_addr.mem_handle,
 			g_tfe_hw_mgr.mgr_common.cmd_iommu_hdl,
 			&ctx->last_submit_bl_cmd.cmd[i].hw_addr,
-			&ctx->last_submit_bl_cmd.cmd[i].len);
+			&ctx->last_submit_bl_cmd.cmd[i].len, NULL);
 		} else if (cdm_cmd->type ==
 			CAM_CDM_BL_CMD_TYPE_HW_IOVA) {
 			if (!cdm_cmd->cmd[i].bl_addr.hw_iova) {
@@ -4801,7 +4801,7 @@ static void cam_tfe_mgr_print_io_bufs(struct cam_tfe_hw_mgr  *hw_mgr,
 			io_cfg[i].mem_handle[j]) ? sec_mmu_hdl :
 			iommu_hdl;
 		rc = cam_mem_get_io_buf(io_cfg[i].mem_handle[j],
-			mmu_hdl, &iova_addr, &src_buf_size);
+			mmu_hdl, &iova_addr, &src_buf_size, NULL);
 		if (rc < 0) {
 			CAM_ERR(CAM_ISP,
 				"get src buf address fail mem_handle 0x%x",

+ 2 - 2
drivers/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c

@@ -895,7 +895,7 @@ int cam_isp_add_io_buffers(
 
 				rc = cam_mem_get_io_buf(
 					io_cfg[i].mem_handle[plane_id],
-					mmu_hdl, &io_addr[plane_id], &size);
+					mmu_hdl, &io_addr[plane_id], &size, NULL);
 				if (rc) {
 					CAM_ERR(CAM_ISP,
 						"no io addr for plane%d",
@@ -1055,7 +1055,7 @@ int cam_isp_add_io_buffers(
 
 				rc = cam_mem_get_io_buf(
 					io_cfg[i].mem_handle[plane_id],
-					mmu_hdl, &io_addr[plane_id], &size);
+					mmu_hdl, &io_addr[plane_id], &size, NULL);
 				if (rc) {
 					CAM_ERR(CAM_ISP,
 						"no io addr for plane%d",

+ 73 - 42
drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver3.c

@@ -23,6 +23,8 @@
 #include "cam_debug_util.h"
 #include "cam_cpas_api.h"
 #include "cam_trace.h"
+#include "cam_smmu_api.h"
+#include "cam_common_util.h"
 
 static const char drv_name[] = "vfe_bus";
 
@@ -2894,15 +2896,22 @@ static void cam_vfe_bus_ver3_update_ubwc_meta_addr(
 	dma_addr_t  image_buf)
 {
 	struct cam_vfe_bus_ver3_reg_offset_ubwc_client *ubwc_regs;
+	uint32_t temp = cam_smmu_is_expanded_memory() ?
+		CAM_36BIT_INTF_GET_IOVA_BASE(image_buf) : image_buf;
+
+	if (cam_smmu_is_expanded_memory() &&
+		CAM_36BIT_INTF_GET_IOVA_OFFSET(image_buf)) {
+		CAM_ERR(CAM_ISP, "Error, address not aligned! offset:0x%x",
+			CAM_36BIT_INTF_GET_IOVA_OFFSET(image_buf));
+	}
 
 	if (!regs || !reg_val_pair || !j) {
 		CAM_ERR(CAM_ISP, "Invalid args");
 		goto end;
 	}
 
-	ubwc_regs = (struct cam_vfe_bus_ver3_reg_offset_ubwc_client *)regs;
-	CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, *j,
-		ubwc_regs->meta_addr, image_buf);
+	ubwc_regs = (struct cam_vfe_bus_ver3_reg_offset_ubwc_client *) regs;
+	CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, *j, ubwc_regs->meta_addr, temp);
 
 end:
 	return;
@@ -2993,12 +3002,14 @@ static int cam_vfe_bus_ver3_update_wm(void *priv, void *cmd_args,
 	struct cam_cdm_utils_ops                       *cdm_util_ops;
 	uint32_t *reg_val_pair;
 	uint32_t num_regval_pairs = 0;
-	uint32_t  i, j, k, size = 0;
-	uint32_t  frame_inc = 0, val;
+	uint32_t i, j, k, size = 0;
+	uint32_t frame_inc = 0, val;
 	uint32_t loop_size = 0;
+	uint32_t iova_addr, iova_offset, image_buf_offset = 0;
+	dma_addr_t iova;
 
 	bus_priv = (struct cam_vfe_bus_ver3_priv  *) priv;
-	update_buf =  (struct cam_isp_hw_get_cmd_update *) cmd_args;
+	update_buf = (struct cam_isp_hw_get_cmd_update *) cmd_args;
 
 	vfe_out_data = (struct cam_vfe_bus_ver3_vfe_out_data *)
 		update_buf->res->res_priv;
@@ -3036,22 +3047,34 @@ static int cam_vfe_bus_ver3_update_wm(void *priv, void *cmd_args,
 			wm_data->en_cfg &= ~(1 << 2);
 
 		if (update_buf->wm_update->frame_header &&
-			!update_buf->wm_update->fh_enabled) {
-			if (wm_data->hw_regs->frame_header_addr) {
-				wm_data->en_cfg |= 1 << 2;
-				update_buf->wm_update->fh_enabled = true;
-				CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
-						wm_data->hw_regs->frame_header_addr,
-						update_buf->wm_update->frame_header);
-				CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
-						wm_data->hw_regs->frame_header_cfg,
-						update_buf->wm_update->local_id);
-				CAM_DBG(CAM_ISP,
-					"WM: %d en_cfg 0x%x frame_header %pK local_id %u",
-					wm_data->index, wm_data->en_cfg,
-					update_buf->wm_update->frame_header,
-					update_buf->wm_update->local_id);
+			!update_buf->wm_update->fh_enabled &&
+			wm_data->hw_regs->frame_header_addr) {
+
+			wm_data->en_cfg |= 1 << 2;
+			update_buf->wm_update->fh_enabled = true;
+			if (cam_smmu_is_expanded_memory()) {
+				iova_addr = CAM_36BIT_INTF_GET_IOVA_BASE(
+					update_buf->wm_update->frame_header);
+				iova_offset = CAM_36BIT_INTF_GET_IOVA_OFFSET(
+					update_buf->wm_update->frame_header);
+			} else {
+				iova_addr = update_buf->wm_update->frame_header;
+				iova_offset = 0;
 			}
+
+			if (iova_offset)
+				CAM_ERR(CAM_ISP, "Error, address not aligned! offset:0x%x",
+					iova_offset);
+			CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
+				wm_data->hw_regs->frame_header_addr, iova_addr);
+			CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
+				wm_data->hw_regs->frame_header_cfg,
+				update_buf->wm_update->local_id);
+			CAM_DBG(CAM_ISP,
+				"WM: %d en_cfg 0x%x frame_header %pK local_id %u",
+				wm_data->index, wm_data->en_cfg,
+				update_buf->wm_update->frame_header,
+				update_buf->wm_update->local_id);
 		}
 
 		CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
@@ -3107,7 +3130,7 @@ static int cam_vfe_bus_ver3_update_wm(void *priv, void *cmd_args,
 
 		if (wm_data->en_ubwc) {
 			frame_inc = ALIGNUP(io_cfg->planes[i].plane_stride *
-			    io_cfg->planes[i].slice_height, 4096);
+				io_cfg->planes[i].slice_height, 4096);
 			frame_inc += io_cfg->planes[i].meta_size;
 			CAM_DBG(CAM_ISP,
 				"WM:%d frm %d: ht: %d stride %d meta: %d",
@@ -3133,35 +3156,43 @@ static int cam_vfe_bus_ver3_update_wm(void *priv, void *cmd_args,
 		else
 			loop_size = 1;
 
+		if (wm_data->en_ubwc)
+			image_buf_offset = io_cfg->planes[i].meta_size;
+		else if (wm_data->en_cfg & (0x3 << 16))
+			image_buf_offset = wm_data->offset;
+		else
+			image_buf_offset = 0;
+
 		/* WM Image address */
 		for (k = 0; k < loop_size; k++) {
-			if (wm_data->en_ubwc) {
+			iova = update_buf->wm_update->image_buf[i] +
+				image_buf_offset + (k * frame_inc);
+
+			if (cam_smmu_is_expanded_memory()) {
+				iova_addr = CAM_36BIT_INTF_GET_IOVA_BASE(iova);
+				iova_offset = CAM_36BIT_INTF_GET_IOVA_OFFSET(iova);
+
 				CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
-					wm_data->hw_regs->image_addr,
-					update_buf->wm_update->image_buf[i] +
-					io_cfg->planes[i].meta_size +
-					k * frame_inc);
-				update_buf->wm_update->image_buf_offset[i] =
-					io_cfg->planes[i].meta_size;
-			} else if (wm_data->en_cfg & (0x3 << 16)) {
+					wm_data->hw_regs->image_addr, iova_addr);
+
 				CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
-					wm_data->hw_regs->image_addr,
-					(update_buf->wm_update->image_buf[i] +
-					wm_data->offset + k * frame_inc));
-				update_buf->wm_update->image_buf_offset[i] =
-					wm_data->offset;
+					wm_data->hw_regs->addr_cfg, iova_offset);
+
+				CAM_DBG(CAM_ISP, "WM:%d image address 0x%X 0x%X",
+					wm_data->index, reg_val_pair[j-2], reg_val_pair[j-1]);
 			} else {
+				iova_addr = iova;
+
 				CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
-					wm_data->hw_regs->image_addr,
-					(update_buf->wm_update->image_buf[i] +
-					k * frame_inc));
-				update_buf->wm_update->image_buf_offset[i] = 0;
-			}
+					wm_data->hw_regs->image_addr, iova_addr);
 
-			CAM_DBG(CAM_ISP, "WM:%d image address 0x%X",
-				wm_data->index, reg_val_pair[j-1]);
+				CAM_DBG(CAM_ISP, "WM:%d image address 0x%X",
+					wm_data->index, reg_val_pair[j-1]);
+			}
 		}
 
+		update_buf->wm_update->image_buf_offset[i] = image_buf_offset;
+
 		CAM_VFE_ADD_REG_VAL_PAIR(reg_val_pair, j,
 			wm_data->hw_regs->frame_incr, frame_inc);
 		CAM_DBG(CAM_ISP, "WM:%d frame_inc %d",

+ 1 - 1
drivers/cam_jpeg/jpeg_hw/cam_jpeg_hw_mgr.c

@@ -741,7 +741,7 @@ static void cam_jpeg_mgr_print_io_bufs(struct cam_packet *packet,
 				io_cfg[i].mem_handle[j]) ? sec_mmu_hdl :
 				iommu_hdl;
 			rc = cam_mem_get_io_buf(io_cfg[i].mem_handle[j],
-				mmu_hdl, &iova_addr, &src_buf_size);
+				mmu_hdl, &iova_addr, &src_buf_size, NULL);
 			if (rc < 0) {
 				CAM_ERR(CAM_UTIL, "get src buf address fail");
 				continue;

+ 2 - 2
drivers/cam_lrme/lrme_hw_mgr/cam_lrme_hw_mgr.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/module.h>
@@ -167,7 +167,7 @@ static int cam_lrme_mgr_util_prepare_io_buffer(int32_t iommu_hdl,
 				break;
 
 			rc = cam_mem_get_io_buf(io_cfg[i].mem_handle[plane],
-				iommu_hdl, &io_addr[plane], &size);
+				iommu_hdl, &io_addr[plane], &size, NULL);
 			if (rc) {
 				CAM_ERR(CAM_LRME, "Cannot get io buf for %d %d",
 					plane, rc);

+ 9 - 11
drivers/cam_ope/ope_hw_mgr/cam_ope_hw_mgr.c

@@ -354,7 +354,7 @@ static int cam_ope_dump_hang_patches(struct cam_packet *packet,
 
 	for (i = 0; i < packet->num_patches; i++) {
 		rc = cam_mem_get_io_buf(patch_desc[i].src_buf_hdl,
-			iommu_hdl, &iova_addr, &src_buf_size);
+			iommu_hdl, &iova_addr, &src_buf_size, NULL);
 		if (rc < 0) {
 			CAM_ERR(CAM_UTIL,
 				"get src buf address failed for handle 0x%x",
@@ -380,7 +380,7 @@ static int cam_ope_dump_direct(struct ope_cmd_buf_info *cmd_buf_info,
 	int rc = 0;
 
 	rc = cam_mem_get_io_buf(cmd_buf_info->mem_handle,
-		ope_hw_mgr->iommu_hdl, &iova_addr, &size);
+		ope_hw_mgr->iommu_hdl, &iova_addr, &size, NULL);
 	if (rc < 0) {
 		CAM_ERR(CAM_UTIL, "get cmd buf addressfailed for handle 0x%x",
 			cmd_buf_info->mem_handle);
@@ -498,7 +498,7 @@ static int cam_ope_mgr_dump_frame_set(uintptr_t frame_process_addr,
 		for (i = 0; i < frame_process->frame_set[j].num_io_bufs; i++) {
 			io_buf = &frame_process->frame_set[j].io_buf[i];
 			rc = cam_mem_get_io_buf(io_buf->mem_handle[0],
-				ope_hw_mgr->iommu_hdl, &iova_addr, &size);
+				ope_hw_mgr->iommu_hdl, &iova_addr, &size, NULL);
 			if (rc) {
 				CAM_ERR(CAM_OPE, "get io buf fail 0x%x",
 					io_buf->mem_handle[0]);
@@ -572,7 +572,7 @@ static int cam_ope_dump_bls(struct cam_ope_request *ope_req,
 	cdm_cmd = ope_req->cdm_cmd;
 	for (i = 0; i < cdm_cmd->cmd_arrary_count; i++) {
 		rc = cam_mem_get_io_buf(cdm_cmd->cmd[i].bl_addr.mem_handle,
-				ope_hw_mgr->iommu_hdl, &iova_addr, &size);
+				ope_hw_mgr->iommu_hdl, &iova_addr, &size, NULL);
 		if (rc) {
 			CAM_ERR(CAM_OPE, "get io buf fail 0x%x",
 				cdm_cmd->cmd[i].bl_addr.mem_handle);
@@ -2012,12 +2012,12 @@ static int cam_ope_mgr_process_cmd_io_buf_req(struct cam_ope_hw_mgr *hw_mgr,
 					rc = cam_mem_get_io_buf(
 						in_io_buf->mem_handle[k],
 						hw_mgr->iommu_sec_hdl,
-						&iova_addr, &len);
+						&iova_addr, &len, NULL);
 				else
 					rc = cam_mem_get_io_buf(
 						in_io_buf->mem_handle[k],
 						hw_mgr->iommu_hdl,
-						&iova_addr, &len);
+						&iova_addr, &len, NULL);
 
 				if (rc) {
 					CAM_ERR(CAM_OPE, "get buf failed: %d",
@@ -2137,7 +2137,7 @@ static int cam_ope_mgr_process_cmd_buf_req(struct cam_ope_hw_mgr *hw_mgr,
 			switch (cmd_buf->cmd_buf_scope) {
 			case OPE_CMD_BUF_SCOPE_FRAME: {
 				rc = cam_mem_get_io_buf(cmd_buf->mem_handle,
-					hw_mgr->iommu_hdl, &iova_addr, &len);
+					hw_mgr->iommu_hdl, &iova_addr, &len, NULL);
 				if (rc) {
 					CAM_ERR(CAM_OPE, "get cmd buffailed %x",
 						hw_mgr->iommu_hdl);
@@ -2146,8 +2146,7 @@ static int cam_ope_mgr_process_cmd_buf_req(struct cam_ope_hw_mgr *hw_mgr,
 				iova_addr = iova_addr + cmd_buf->offset;
 
 				rc = cam_mem_get_io_buf(cmd_buf->mem_handle,
-					hw_mgr->iommu_cdm_hdl,
-					&iova_cdm_addr, &len);
+					hw_mgr->iommu_cdm_hdl, &iova_cdm_addr, &len, NULL);
 				if (rc) {
 					CAM_ERR(CAM_OPE, "get cmd buffailed %x",
 						hw_mgr->iommu_hdl);
@@ -4211,7 +4210,7 @@ iodump:
 					hw_mgr->iommu_sec_hdl :
 					hw_mgr->iommu_hdl;
 			rc = cam_mem_get_io_buf(io_cfg[i].mem_handle[j],
-					mmu_hdl, &iova_addr, &src_buf_size);
+					mmu_hdl, &iova_addr, &src_buf_size, NULL);
 			if (rc < 0) {
 				CAM_ERR(CAM_UTIL, "get src buf address fail");
 				continue;
@@ -4248,4 +4247,3 @@ iodump:
 			return;
 	}
 }
-

+ 3 - 5
drivers/cam_ope/ope_hw_mgr/ope_hw/ope_core.c

@@ -548,7 +548,7 @@ static uint32_t *ope_create_frame_cmd_batch(struct cam_ope_hw_mgr *hw_mgr,
 
 		rc = cam_mem_get_io_buf(
 			frm_proc->cmd_buf[i][j].mem_handle,
-			hw_mgr->iommu_cdm_hdl, &iova_addr, &buf_len);
+			hw_mgr->iommu_cdm_hdl, &iova_addr, &buf_len, NULL);
 		if (rc) {
 			CAM_ERR(CAM_OPE, "get cmd buf failed %x",
 				hw_mgr->iommu_hdl);
@@ -705,7 +705,7 @@ static uint32_t *ope_create_frame_cmd(struct cam_ope_hw_mgr *hw_mgr,
 
 			rc = cam_mem_get_io_buf(
 				frm_proc->cmd_buf[i][j].mem_handle,
-				hw_mgr->iommu_cdm_hdl, &iova_addr, &buf_len);
+				hw_mgr->iommu_cdm_hdl, &iova_addr, &buf_len, NULL);
 			if (rc) {
 				CAM_ERR(CAM_OPE, "get cmd buf failed %x",
 					hw_mgr->iommu_hdl);
@@ -820,8 +820,7 @@ static uint32_t *ope_create_stripe_cmd(struct cam_ope_hw_mgr *hw_mgr,
 
 		CAM_DBG(CAM_OPE, "process stripe %d", stripe_idx);
 		rc = cam_mem_get_io_buf(frm_proc->cmd_buf[i][k].mem_handle,
-			hw_mgr->iommu_cdm_hdl,
-			&iova_addr, &buf_len);
+			hw_mgr->iommu_cdm_hdl, &iova_addr, &buf_len, NULL);
 		if (rc) {
 			CAM_DBG(CAM_OPE, "get cmd buf fail %x",
 				hw_mgr->iommu_hdl);
@@ -1804,4 +1803,3 @@ irqreturn_t cam_ope_irq(int irq_num, void *data)
 
 	return IRQ_HANDLED;
 }
-

+ 10 - 15
drivers/cam_req_mgr/cam_mem_mgr.c

@@ -256,7 +256,7 @@ static void cam_mem_put_slot(int32_t idx)
 }
 
 int cam_mem_get_io_buf(int32_t buf_handle, int32_t mmu_handle,
-	dma_addr_t *iova_ptr, size_t *len_ptr)
+	dma_addr_t *iova_ptr, size_t *len_ptr, uint32_t *flags)
 {
 	int rc = 0, idx;
 
@@ -284,15 +284,11 @@ int cam_mem_get_io_buf(int32_t buf_handle, int32_t mmu_handle,
 	}
 
 	if (CAM_MEM_MGR_IS_SECURE_HDL(buf_handle))
-		rc = cam_smmu_get_stage2_iova(mmu_handle,
-			tbl.bufq[idx].fd,
-			iova_ptr,
-			len_ptr);
+		rc = cam_smmu_get_stage2_iova(mmu_handle, tbl.bufq[idx].fd,
+			iova_ptr, len_ptr);
 	else
-		rc = cam_smmu_get_iova(mmu_handle,
-			tbl.bufq[idx].fd,
-			iova_ptr,
-			len_ptr);
+		rc = cam_smmu_get_iova(mmu_handle, tbl.bufq[idx].fd,
+			iova_ptr, len_ptr);
 	if (rc) {
 		CAM_ERR(CAM_MEM,
 			"fail to map buf_hdl:0x%x, mmu_hdl: 0x%x for fd:%d",
@@ -300,6 +296,9 @@ int cam_mem_get_io_buf(int32_t buf_handle, int32_t mmu_handle,
 		goto handle_mismatch;
 	}
 
+	if (flags)
+		*flags = tbl.bufq[idx].flags;
+
 	CAM_DBG(CAM_MEM,
 		"handle:0x%x fd:%d iova_ptr:0x%llx len_ptr:%llu",
 		mmu_handle, tbl.bufq[idx].fd, iova_ptr, *len_ptr);
@@ -318,11 +317,6 @@ int cam_mem_get_cpu_buf(int32_t buf_handle, uintptr_t *vaddr_ptr, size_t *len)
 		return -EINVAL;
 	}
 
-	if (!atomic_read(&cam_mem_mgr_state)) {
-		CAM_ERR(CAM_MEM, "failed. mem_mgr not initialized");
-		return -EINVAL;
-	}
-
 	if (!buf_handle || !vaddr_ptr || !len)
 		return -EINVAL;
 
@@ -926,7 +920,8 @@ int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd)
 			region = CAM_SMMU_REGION_IO;
 
 
-		if (cmd->flags & CAM_MEM_FLAG_HW_SHARED_ACCESS)
+		if (cmd->flags & CAM_MEM_FLAG_HW_SHARED_ACCESS ||
+			(cam_smmu_is_expanded_memory() && cmd->flags & CAM_MEM_FLAG_CMD_BUF_TYPE))
 			region = CAM_SMMU_REGION_SHARED;
 
 		if (cmd->flags & CAM_MEM_FLAG_PROTECTED_MODE)

+ 2 - 1
drivers/cam_req_mgr/cam_mem_mgr_api.h

@@ -70,11 +70,12 @@ int cam_mem_mgr_release_mem(struct cam_mem_mgr_memory_desc *inp);
  * @mmu_handle: SMMU handle where buffer is mapped
  * @iova_ptr  : Pointer to mmu's iova
  * @len_ptr   : Length of the buffer
+ * @flags     : Flags the buffer was allocated with
  *
  * @return Status of operation. Negative in case of error. Zero otherwise.
  */
 int cam_mem_get_io_buf(int32_t buf_handle, int32_t mmu_handle,
-	dma_addr_t *iova_ptr, size_t *len_ptr);
+	dma_addr_t *iova_ptr, size_t *len_ptr, uint32_t *flags);
 
 /**
  * @brief: This indicates begin of CPU access.

+ 9 - 2
drivers/cam_smmu/cam_smmu_api.c

@@ -189,6 +189,7 @@ struct cam_iommu_cb_set {
 	bool map_profile_enable;
 	bool force_cache_allocs;
 	bool need_shared_buffer_padding;
+	bool is_expanded_memory;
 };
 
 static const struct of_device_id msm_cam_smmu_dt_match[] = {
@@ -376,6 +377,11 @@ bool cam_smmu_need_shared_buffer_padding(void)
 	return iommu_cb_set.need_shared_buffer_padding;
 }
 
+bool cam_smmu_is_expanded_memory(void)
+{
+	return iommu_cb_set.is_expanded_memory;
+}
+
 int cam_smmu_need_force_alloc_cached(bool *force_alloc_cached)
 {
 	int idx;
@@ -4333,8 +4339,9 @@ static int cam_smmu_component_bind(struct device *dev,
 	iommu_cb_set.force_cache_allocs =
 		of_property_read_bool(dev->of_node, "force_cache_allocs");
 	iommu_cb_set.need_shared_buffer_padding =
-		of_property_read_bool(dev->of_node,
-		"need_shared_buffer_padding");
+		of_property_read_bool(dev->of_node, "need_shared_buffer_padding");
+	iommu_cb_set.is_expanded_memory =
+		of_property_read_bool(dev->of_node, "expanded_memory");
 
 	CAM_DBG(CAM_SMMU, "Main component bound successfully");
 	return 0;

+ 4 - 0
drivers/cam_smmu/cam_smmu_api.h

@@ -445,5 +445,9 @@ int cam_smmu_need_force_alloc_cached(bool *force_alloc_cached);
  */
 bool cam_smmu_need_shared_buffer_padding(void);
 
+/**
+ * @brief : API to determine whether certain HW is 36-bit memory addressable
+ */
+bool cam_smmu_is_expanded_memory(void);
 
 #endif /* _CAM_SMMU_API_H_ */

+ 23 - 13
drivers/cam_utils/cam_packet_util.c

@@ -9,6 +9,7 @@
 #include "cam_mem_mgr.h"
 #include "cam_packet_util.h"
 #include "cam_debug_util.h"
+#include "cam_common_util.h"
 
 #define CAM_UNIQUE_SRC_HDL_MAX 50
 
@@ -16,6 +17,7 @@ struct cam_patch_unique_src_buf_tbl {
 	int32_t       hdl;
 	dma_addr_t    iova;
 	size_t        buf_size;
+	uint32_t      flags;
 };
 
 int cam_packet_util_get_cmd_mem_addr(int handle, uint32_t **buf_addr,
@@ -173,6 +175,7 @@ void cam_packet_dump_patch_info(struct cam_packet *packet,
 	int32_t    hdl;
 	uintptr_t  cpu_addr = 0;
 	uint32_t  *dst_cpu_addr;
+	uint32_t   flags;
 	uint64_t   value = 0;
 
 	patch_desc = (struct cam_patch_desc *)
@@ -186,7 +189,7 @@ void cam_packet_dump_patch_info(struct cam_packet *packet,
 		hdl = cam_mem_is_secure_buf(patch_desc[i].src_buf_hdl) ?
 			sec_mmu_hdl : iommu_hdl;
 		rc = cam_mem_get_io_buf(patch_desc[i].src_buf_hdl,
-			hdl, &iova_addr, &src_buf_size);
+			hdl, &iova_addr, &src_buf_size, &flags);
 		if (rc < 0) {
 			CAM_ERR(CAM_UTIL,
 				"unable to get src buf address for hdl 0x%x",
@@ -206,10 +209,10 @@ void cam_packet_dump_patch_info(struct cam_packet *packet,
 			patch_desc[i].dst_offset);
 		value = *((uint64_t *)dst_cpu_addr);
 		CAM_INFO(CAM_UTIL,
-			"i = %d src_buf 0x%llx src_hdl 0x%x src_buf_with_offset 0x%llx size 0x%llx dst %p dst_offset %u dst_hdl 0x%x value 0x%llx",
+			"i = %d src_buf 0x%llx src_hdl 0x%x src_buf_with_offset 0x%llx src_size 0x%llx src_flags: %x dst %p dst_offset %u dst_hdl 0x%x value 0x%llx",
 			i, iova_addr, patch_desc[i].src_buf_hdl,
 			(iova_addr + patch_desc[i].src_offset),
-			src_buf_size, dst_cpu_addr,
+			src_buf_size, flags, dst_cpu_addr,
 			patch_desc[i].dst_offset,
 			patch_desc[i].dst_buf_hdl, value);
 
@@ -220,7 +223,8 @@ void cam_packet_dump_patch_info(struct cam_packet *packet,
 
 static int cam_packet_util_get_patch_iova(
 	struct cam_patch_unique_src_buf_tbl *tbl,
-	int32_t hdl, uint32_t buf_hdl, dma_addr_t *iova, size_t *buf_size)
+	int32_t hdl, uint32_t buf_hdl, dma_addr_t *iova,
+	size_t *buf_size, uint32_t *flags)
 {
 	int idx = 0;
 	int rc = 0;
@@ -235,11 +239,11 @@ static int cam_packet_util_get_patch_iova(
 				buf_hdl, idx, tbl[idx].hdl);
 			*iova = tbl[idx].iova;
 			*buf_size = tbl[idx].buf_size;
+			*flags = tbl[idx].flags;
 			is_found = true;
 			break;
 		} else if ((tbl[idx].hdl == 0) || (tbl[idx].iova == 0)) {
-			CAM_DBG(CAM_UTIL, "New src handle detected 0x%x",
-				buf_hdl);
+			CAM_DBG(CAM_UTIL, "New src handle detected 0x%x", buf_hdl);
 			is_found = false;
 			break;
 		}
@@ -251,8 +255,7 @@ static int cam_packet_util_get_patch_iova(
 	if (!is_found) {
 		CAM_DBG(CAM_UTIL, "src_hdl 0x%x not found in table entries",
 			buf_hdl);
-		rc = cam_mem_get_io_buf(buf_hdl, hdl,
-			&iova_addr, &src_buf_size);
+		rc = cam_mem_get_io_buf(buf_hdl, hdl, &iova_addr, &src_buf_size, flags);
 		if (rc < 0) {
 			CAM_ERR(CAM_UTIL,
 				"unable to get iova for src_hdl: 0x%x",
@@ -264,9 +267,10 @@ static int cam_packet_util_get_patch_iova(
 			tbl[idx].buf_size = src_buf_size;
 			tbl[idx].iova = iova_addr;
 			tbl[idx].hdl = buf_hdl;
+			tbl[idx].flags = *flags;
 			CAM_DBG(CAM_UTIL,
-				"Updated table index: %d with src_buf_hdl: 0x%x",
-				idx, tbl[idx].hdl);
+				"Updated table index: %d with src_buf_hdl: 0x%x flags: %x",
+				idx, tbl[idx].hdl, *flags);
 		}
 		*iova = iova_addr;
 		*buf_size = src_buf_size;
@@ -281,12 +285,13 @@ int cam_packet_util_process_patches(struct cam_packet *packet,
 	struct cam_patch_desc *patch_desc = NULL;
 	dma_addr_t iova_addr;
 	uintptr_t  cpu_addr = 0;
-	dma_addr_t   temp;
+	dma_addr_t temp;
 	uint32_t  *dst_cpu_addr;
 	size_t     dst_buf_len;
 	size_t     src_buf_size;
 	int        i  = 0;
 	int        rc = 0;
+	uint32_t   flags = 0;
 	int32_t    hdl;
 	struct cam_patch_unique_src_buf_tbl
 		tbl[CAM_UNIQUE_SRC_HDL_MAX];
@@ -307,7 +312,7 @@ int cam_packet_util_process_patches(struct cam_packet *packet,
 			sec_mmu_hdl : iommu_hdl;
 
 		rc = cam_packet_util_get_patch_iova(&tbl[0], hdl,
-			patch_desc[i].src_buf_hdl, &iova_addr, &src_buf_size);
+			patch_desc[i].src_buf_hdl, &iova_addr, &src_buf_size, &flags);
 		if (rc) {
 			CAM_ERR(CAM_UTIL,
 				"get_iova failed for patch[%d], src_buf_hdl: 0x%x: rc: %d",
@@ -348,7 +353,12 @@ int cam_packet_util_process_patches(struct cam_packet *packet,
 			patch_desc[i].dst_offset);
 		temp += patch_desc[i].src_offset;
 
-		*dst_cpu_addr = temp;
+		if ((flags & CAM_MEM_FLAG_HW_SHARED_ACCESS) ||
+			(flags & CAM_MEM_FLAG_CMD_BUF_TYPE))
+			*dst_cpu_addr = temp;
+		else
+			*dst_cpu_addr = cam_smmu_is_expanded_memory() ?
+				CAM_36BIT_INTF_GET_IOVA_BASE(temp) : temp;
 
 		CAM_DBG(CAM_UTIL,
 			"patch is done for dst %pk with src 0x%llx value 0x%llx",