From 12548365dfc565cbbed5a2b86662e8aa227f3c8c Mon Sep 17 00:00:00 2001 From: Ravikishore Pampana Date: Fri, 15 Nov 2019 09:31:24 +0530 Subject: [PATCH] msm: camera: common: secure camera fixes Isp bus port secure mode not coming properly. Added proper logic to get the bus port secure mode correctly. Use secure iommu handle to get secure buffer for ope. Add spin lock for tfe irq handler. Use proper bw structure to copy the user send blob data. CRs-Fixed: 2594541 Change-Id: Icb8ecf869681c370efa084991505036f90a35065 Signed-off-by: Ravikishore Pampana --- drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c | 2 +- drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c | 4 ++-- .../hw_utils/cam_isp_packet_parser.c | 20 ++++++++++++++++--- .../isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_bus.c | 17 ++++++++-------- .../isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_core.c | 2 ++ .../isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c | 12 ++++++----- .../isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver3.c | 11 +++++----- drivers/cam_ope/ope_hw_mgr/cam_ope_hw_mgr.c | 17 +++++++++++++--- 8 files changed, 58 insertions(+), 27 deletions(-) diff --git a/drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c b/drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c index 6fdc18b05306..4baf5f37ac38 100644 --- a/drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c +++ b/drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c @@ -5230,7 +5230,7 @@ static int cam_isp_packet_generic_blob_handler(void *user_data, memset(&prepare_hw_data->bw_config_v2[bw_config->usage_type], 0, sizeof( prepare_hw_data->bw_config_v2[bw_config->usage_type])); - bw_config_size = sizeof(struct cam_isp_bw_config_internal_v2) + + bw_config_size = sizeof(struct cam_isp_bw_config_v2) + ((bw_config->num_paths - 1) * sizeof(struct cam_axi_per_path_bw_vote)); memcpy(&prepare_hw_data->bw_config_v2[bw_config->usage_type], diff --git a/drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c b/drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c index c89d6d56479e..0eaa8df2559e 100644 --- a/drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c +++ b/drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c @@ -2354,7 +2354,7 @@ static int cam_tfe_mgr_config_hw(void *hw_mgr_priv, if (hw_update_data->bw_config_valid[i] == true) { CAM_DBG(CAM_ISP, "idx=%d, bw_config_version=%d", - ctx, ctx->ctx_index, i, + ctx->ctx_index, i, hw_update_data->bw_config_version); if (hw_update_data->bw_config_version == CAM_ISP_BW_CONFIG_V2) { @@ -3486,7 +3486,7 @@ static int cam_isp_tfe_packet_generic_blob_handler(void *user_data, memset(&prepare_hw_data->bw_config_v2[bw_config->usage_type], 0, sizeof( prepare_hw_data->bw_config_v2[bw_config->usage_type])); - bw_config_size = sizeof(struct cam_isp_bw_config_internal_v2) + + bw_config_size = sizeof(struct cam_isp_tfe_bw_config_v2) + ((bw_config->num_paths - 1) * sizeof(struct cam_axi_per_path_bw_vote)); memcpy(&prepare_hw_data->bw_config_v2[bw_config->usage_type], diff --git a/drivers/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c b/drivers/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c index 67211e60517e..ce3f895f4bd8 100644 --- a/drivers/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c +++ b/drivers/cam_isp/isp_hw_mgr/hw_utils/cam_isp_packet_parser.c @@ -475,6 +475,7 @@ int cam_isp_add_io_buffers( struct cam_isp_hw_get_wm_update bus_rd_update; struct cam_hw_fence_map_entry *out_map_entries; struct cam_hw_fence_map_entry *in_map_entries; + struct cam_isp_hw_get_cmd_update secure_mode; uint32_t kmd_buf_remain_size; uint32_t i, j, num_out_buf, num_in_buf; uint32_t res_id_out, res_id_in, plane_id; @@ -482,7 +483,8 @@ int cam_isp_add_io_buffers( size_t size; int32_t hdl; int mmu_hdl; - bool mode, is_buf_secure; + bool is_buf_secure; + uint32_t mode; io_cfg = (struct cam_buf_io_cfg *) ((uint8_t *) &prepare->packet->payload + @@ -611,10 +613,16 @@ int cam_isp_add_io_buffers( break; hdl = io_cfg[i].mem_handle[plane_id]; + secure_mode.cmd_type = + CAM_ISP_HW_CMD_GET_SECURE_MODE; + secure_mode.res = res; + secure_mode.data = (void *)&mode; rc = res->hw_intf->hw_ops.process_cmd( res->hw_intf->hw_priv, CAM_ISP_HW_CMD_GET_SECURE_MODE, - &mode, sizeof(bool)); + &secure_mode, + sizeof( + struct cam_isp_hw_get_cmd_update)); if (rc) return -EINVAL; @@ -722,10 +730,16 @@ int cam_isp_add_io_buffers( break; hdl = io_cfg[i].mem_handle[plane_id]; + secure_mode.cmd_type = + CAM_ISP_HW_CMD_GET_SECURE_MODE; + secure_mode.res = res; + secure_mode.data = (void *)&mode; rc = res->hw_intf->hw_ops.process_cmd( res->hw_intf->hw_priv, CAM_ISP_HW_CMD_GET_SECURE_MODE, - &mode, sizeof(bool)); + &secure_mode, + sizeof( + struct cam_isp_hw_get_cmd_update)); if (rc) return -EINVAL; diff --git a/drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_bus.c b/drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_bus.c index a4eebd5a6e51..36980990f8af 100644 --- a/drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_bus.c +++ b/drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_bus.c @@ -1043,12 +1043,13 @@ static int cam_tfe_bus_deinit_comp_grp( static int cam_tfe_bus_get_secure_mode(void *priv, void *cmd_args, uint32_t arg_size) { - bool *mode = cmd_args; - struct cam_isp_resource_node *res = - (struct cam_isp_resource_node *) priv; - struct cam_tfe_bus_tfe_out_data *rsrc_data = - (struct cam_tfe_bus_tfe_out_data *)res->res_priv; + struct cam_isp_hw_get_cmd_update *secure_mode = cmd_args; + struct cam_tfe_bus_tfe_out_data *rsrc_data; + uint32_t *mode; + rsrc_data = (struct cam_tfe_bus_tfe_out_data *) + secure_mode->res->res_priv; + mode = (uint32_t *)secure_mode->data; *mode = (rsrc_data->secure_mode == CAM_SECURE_MODE_SECURE) ? true : false; @@ -1657,7 +1658,7 @@ static int cam_tfe_bus_update_wm(void *priv, void *cmd_args, wm_data->index, reg_val_pair[j-1]); val = io_cfg->planes[i].plane_stride; - CAM_DBG(CAM_ISP, "before stride %d", val); + CAM_DBG(CAM_ISP, "before stride 0x%x", val); val = ALIGNUP(val, 16); if (val != io_cfg->planes[i].plane_stride && val != wm_data->stride) @@ -1674,7 +1675,7 @@ static int cam_tfe_bus_update_wm(void *priv, void *cmd_args, CAM_TFE_ADD_REG_VAL_PAIR(reg_val_pair, j, wm_data->hw_regs->image_cfg_2, io_cfg->planes[i].plane_stride); - wm_data->stride = val; + wm_data->stride = io_cfg->planes[i].plane_stride; CAM_DBG(CAM_ISP, "WM %d image stride 0x%x", wm_data->index, reg_val_pair[j-1]); } @@ -1833,7 +1834,7 @@ static int cam_tfe_bus_update_stripe_cfg(void *priv, void *cmd_args, wm_data = tfe_out_data->wm_res[i]->res_priv; wm_data->width = stripe_config->width; wm_data->offset = stripe_config->offset; - CAM_DBG(CAM_ISP, "id:%x WM:%d width:0x%x offset:%x", + CAM_DBG(CAM_ISP, "id:%x WM:%d width:0x%x offset:0x%x", stripe_args->res->res_id, wm_data->index, wm_data->width, wm_data->offset); } diff --git a/drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_core.c b/drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_core.c index 99fc55b10bc1..8ebabf1f15c4 100644 --- a/drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_core.c +++ b/drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_core.c @@ -702,6 +702,7 @@ irqreturn_t cam_tfe_irq(int irq_num, void *data) return IRQ_HANDLED; } + spin_lock(&core_info->spin_lock); for (i = 0; i < CAM_TFE_TOP_IRQ_REG_NUM; i++) top_irq_status[i] = cam_io_r(mem_base + core_info->tfe_hw_info->top_irq_status[i]); @@ -740,6 +741,7 @@ irqreturn_t cam_tfe_irq(int irq_num, void *data) core_info->core_index, bus_irq_status[0], bus_irq_status[1]); } + spin_unlock(&core_info->spin_lock); /* check reset */ if ((top_irq_status[0] & core_info->tfe_hw_info->reset_irq_mask[0]) || diff --git a/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c b/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c index c5765c8a76a4..9c72e88c6f84 100644 --- a/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c +++ b/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver2.c @@ -1980,12 +1980,14 @@ static int cam_vfe_bus_deinit_comp_grp( static int cam_vfe_bus_get_secure_mode(void *priv, void *cmd_args, uint32_t arg_size) { - bool *mode = cmd_args; - struct cam_isp_resource_node *res = - (struct cam_isp_resource_node *) priv; - struct cam_vfe_bus_ver2_vfe_out_data *rsrc_data = - (struct cam_vfe_bus_ver2_vfe_out_data *)res->res_priv; + struct cam_isp_hw_get_cmd_update *secure_mode = cmd_args; + struct cam_vfe_bus_ver2_vfe_out_data *rsrc_data; + uint32_t *mode; + + rsrc_data = (struct cam_vfe_bus_ver2_vfe_out_data *) + secure_mode->res->res_priv; + mode = (uint32_t *)secure_mode->data; *mode = (rsrc_data->secure_mode == CAM_SECURE_MODE_SECURE) ? true : false; diff --git a/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver3.c b/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver3.c index 694dd224a660..3d8415b0f765 100644 --- a/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver3.c +++ b/drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/vfe_bus/cam_vfe_bus_ver3.c @@ -1865,12 +1865,13 @@ static int cam_vfe_bus_ver3_deinit_comp_grp( static int cam_vfe_bus_ver3_get_secure_mode(void *priv, void *cmd_args, uint32_t arg_size) { - bool *mode = cmd_args; - struct cam_isp_resource_node *res = - (struct cam_isp_resource_node *) priv; - struct cam_vfe_bus_ver3_vfe_out_data *rsrc_data = - (struct cam_vfe_bus_ver3_vfe_out_data *)res->res_priv; + struct cam_isp_hw_get_cmd_update *secure_mode = cmd_args; + struct cam_vfe_bus_ver3_vfe_out_data *rsrc_data; + uint32_t *mode; + rsrc_data = (struct cam_vfe_bus_ver3_vfe_out_data *) + secure_mode->res->res_priv; + mode = (uint32_t *)secure_mode->data; *mode = (rsrc_data->secure_mode == CAM_SECURE_MODE_SECURE) ? true : false; diff --git a/drivers/cam_ope/ope_hw_mgr/cam_ope_hw_mgr.c b/drivers/cam_ope/ope_hw_mgr/cam_ope_hw_mgr.c index 4d369b69193d..3671a008fd48 100644 --- a/drivers/cam_ope/ope_hw_mgr/cam_ope_hw_mgr.c +++ b/drivers/cam_ope/ope_hw_mgr/cam_ope_hw_mgr.c @@ -1383,6 +1383,7 @@ static int cam_ope_mgr_process_cmd_io_buf_req(struct cam_ope_hw_mgr *hw_mgr, uint32_t unpack_format; struct ope_in_res_info *in_res; struct ope_out_res_info *out_res; + bool is_secure; in_frame_process = (struct ope_frame_process *)frame_process_addr; @@ -1471,9 +1472,19 @@ static int cam_ope_mgr_process_cmd_io_buf_req(struct cam_ope_hw_mgr *hw_mgr, for (k = 0; k < in_io_buf->num_planes; k++) { io_buf->num_stripes[k] = in_io_buf->num_stripes[k]; - rc = cam_mem_get_io_buf( - in_io_buf->mem_handle[k], - hw_mgr->iommu_hdl, &iova_addr, &len); + is_secure = cam_mem_is_secure_buf( + in_io_buf->mem_handle[k]); + if (is_secure) + rc = cam_mem_get_io_buf( + in_io_buf->mem_handle[k], + hw_mgr->iommu_sec_hdl, + &iova_addr, &len); + else + rc = cam_mem_get_io_buf( + in_io_buf->mem_handle[k], + hw_mgr->iommu_hdl, + &iova_addr, &len); + if (rc) { CAM_ERR(CAM_OPE, "get buf failed: %d", rc);