Przeglądaj źródła

msm: camera: isp: Add domain-id support

This change adds domain-id support for new
targets. This change involves adding information
to the SCM call currently in use such that it is
a superset, and the additional fields needed are
the IFE and CDM number being used, and VC mask.
These are in addition to existing PHY mask selection,
and lane/trio mask selection.

All the information above will be sent over from CSID
to the PHY driver, and the PHY driver will pack the
information in a generic format before sending it
over in an SCM call. Where previously, this information
is packed in format that matches the register, this
will be sent generically moving forward.

Given that there are multiple instances per physical
PHY hardware, and that the usual dev_handle used by
userspace to identify them are not accessible CSID
side, the lane_assign/lane_cfg parameter is used to find
the specific PHY instance used in conjunction with the
CSID instance in a session. lane_assign from PHY driver
and lane_cfg from CSID have the same values.

CRs-Fixed: 3259706
Change-Id: Ie050b1b9e742c6a63812eb38db7eca76db24667f
Signed-off-by: Li Sha Lim <[email protected]>
Li Sha Lim 3 lat temu
rodzic
commit
e1ec8594f4

+ 2 - 0
drivers/cam_cdm/cam_cdm_intf.c

@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/delay.h>
@@ -196,6 +197,7 @@ int cam_cdm_acquire(struct cam_cdm_acquire_data *data)
 			cdm_hw = hw->hw_priv;
 			core = (struct cam_cdm *)cdm_hw->core_info;
 			data->id = core->id;
+			data->hw_idx = hw->hw_idx;
 			CAM_DBG(CAM_CDM,
 				"Device = %s, hw_index = %d, CDM id = %d",
 				data->identifier, hw_index, data->id);

+ 2 - 0
drivers/cam_cdm/cam_cdm_intf_api.h

@@ -89,6 +89,7 @@ enum cam_cdm_bl_fifo_queue {
  * @ops : Output pointer updated by cdm driver to the CDM
  *                     util ops for this HW version of CDM acquired.
  * @handle  : Output Unique handle generated for this acquire
+ * @hw_idx  : The physical CDM acquired
  *
  */
 struct cam_cdm_acquire_data {
@@ -104,6 +105,7 @@ struct cam_cdm_acquire_data {
 	struct cam_hw_version cdm_version;
 	struct cam_cdm_utils_ops *ops;
 	uint32_t handle;
+	uint32_t hw_idx;
 };
 
 /**

+ 18 - 0
drivers/cam_cpas/cam_cpas_intf.c

@@ -785,6 +785,24 @@ int cam_cpas_deactivate_llcc(
 }
 EXPORT_SYMBOL(cam_cpas_deactivate_llcc);
 
+bool cam_cpas_query_domain_id_security_support(void)
+{
+	struct cam_hw_info *cpas_hw = NULL;
+	struct cam_cpas_private_soc *soc_private = NULL;
+
+	if (!CAM_CPAS_INTF_INITIALIZED()) {
+		CAM_ERR(CAM_CPAS, "cpas intf not initialized");
+		return false;
+	}
+
+	cpas_hw = (struct cam_hw_info *) g_cpas_intf->hw_intf->hw_priv;
+	soc_private =
+		(struct cam_cpas_private_soc *)cpas_hw->soc_info.soc_private;
+
+	return soc_private->domain_id_info.domain_id_supported;
+}
+EXPORT_SYMBOL(cam_cpas_query_domain_id_security_support);
+
 int cam_cpas_subdev_cmd(struct cam_cpas_intf *cpas_intf,
 	struct cam_control *cmd)
 {

+ 9 - 0
drivers/cam_cpas/include/cam_cpas_api.h

@@ -889,4 +889,13 @@ int cam_cpas_csid_process_resume(uint32_t csid_idx);
  */
 int cam_cpas_query_drv_enable(bool *is_drv_enabled);
 
+/**
+ * cam_cpas_query_domain_id_security_support()
+ * @brief: API to determine if target supports domain id feature
+ *         This information is determined by cpas during probe
+ *
+ * @return true if there's support, false otherwise
+ */
+bool cam_cpas_query_domain_id_security_support(void);
+
 #endif /* _CAM_CPAS_API_H_ */

+ 40 - 9
drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c

@@ -902,10 +902,11 @@ static int cam_ife_mgr_csid_start_hw(
 	struct cam_hw_intf             *hw_intf;
 	uint32_t  cnt;
 	int j;
-	bool ipp_available = false;
+	bool ipp_available = false, is_secure;
 
 	for (j = ctx->num_base - 1 ; j >= 0; j--) {
 		cnt = 0;
+		is_secure = false;
 
 		if (ctx->base[j].hw_type != CAM_ISP_HW_TYPE_CSID)
 			continue;
@@ -924,9 +925,13 @@ static int cam_ife_mgr_csid_start_hw(
 			if (hw_mgr_res->res_id == CAM_IFE_PIX_PATH_RES_IPP)
 				ipp_available = true;
 
-			CAM_DBG(CAM_ISP, "csid[%u] res:%s res_id %d cnt %u",
+			if (hw_mgr_res->is_secure)
+				is_secure = true;
+
+			CAM_DBG(CAM_ISP, "csid[%u] res:%s res_id %d cnt %u, is_secure: %s",
 				isp_res->hw_intf->hw_idx,
-				isp_res->res_name, isp_res->res_id, cnt);
+				isp_res->res_name, isp_res->res_id, cnt,
+				CAM_BOOL_TO_YESNO(is_secure));
 			res[cnt] = isp_res;
 			cnt++;
 		}
@@ -938,6 +943,16 @@ static int cam_ife_mgr_csid_start_hw(
 			hw_intf =  res[0]->hw_intf;
 			start_args.num_res = cnt;
 			start_args.node_res = res;
+
+			if (ctx->cdm_hw_idx < 0) {
+				CAM_ERR(CAM_ISP,
+					"CSID[%u], physical CDM hw_idx is invalid: %d on ctx: %u",
+					hw_intf->hw_idx, ctx->cdm_hw_idx, ctx->ctx_index);
+				return -EINVAL;
+			}
+
+			start_args.cdm_hw_idx = ctx->cdm_hw_idx;
+			start_args.is_secure = is_secure;
 			start_args.is_internal_start = is_internal_start;
 			hw_intf->hw_ops.start(hw_intf->hw_priv, &start_args,
 			    sizeof(start_args));
@@ -3459,9 +3474,10 @@ static int cam_ife_hw_mgr_acquire_csid_hw(
 				continue;
 			}
 			CAM_DBG(CAM_ISP,
-				"acquired from old csid(%s)=%d successfully",
+				"acquired from old csid(%s)=%d successfully, is_secure: %s",
 				(i == 0) ? "left" : "right",
-				hw_intf->hw_idx);
+				hw_intf->hw_idx,
+				CAM_BOOL_TO_YESNO(csid_res_iterator->is_secure));
 			goto acquire_successful;
 		}
 	}
@@ -3620,9 +3636,10 @@ static int cam_ife_hw_mgr_acquire_res_ife_csid_pxl(
 		ife_ctx->flags.need_csid_top_cfg = csid_acquire.need_top_cfg;
 
 		CAM_DBG(CAM_ISP,
-			"acquired csid(%s)=%d pxl path rsrc %s successfully",
+			"acquired csid(%s)=%d pxl path rsrc %s successfully, is_secure: %s",
 			(i == 0) ? "left" : "right", hw_intf->hw_idx,
-			(is_ipp) ? "IPP" : "PPP");
+			(is_ipp) ? "IPP" : "PPP",
+			CAM_BOOL_TO_YESNO(csid_res->is_secure));
 	}
 
 	if (!is_ipp)
@@ -3799,6 +3816,12 @@ static int cam_ife_hw_mgr_acquire_csid_rdi_util(
 		goto put_res;
 	}
 
+	CAM_DBG(CAM_ISP,
+		"acquired csid[%u] rdi path rsrc %u successfully, is_secure: %s",
+		csid_acquire.node_res->hw_intf->hw_idx,
+		csid_acquire.node_res->res_id,
+		CAM_BOOL_TO_YESNO(csid_res->is_secure));
+
 	ife_ctx->flags.need_csid_top_cfg = csid_acquire.need_top_cfg;
 	csid_res->res_type = CAM_ISP_RESOURCE_PIX_PATH;
 	csid_res->res_id = csid_acquire.res_id;
@@ -5337,6 +5360,7 @@ static int cam_ife_mgr_acquire_hw(void *hw_mgr_priv, void *acquire_hw_args)
 		cdm_acquire.id, cdm_acquire.handle, ife_ctx->flags.is_dual);
 	ife_ctx->cdm_handle = cdm_acquire.handle;
 	ife_ctx->cdm_id = cdm_acquire.id;
+	ife_ctx->cdm_hw_idx = cdm_acquire.hw_idx;
 	if (cdm_acquire.id == CAM_CDM_IFE)
 		ife_ctx->flags.internal_cdm = true;
 	atomic_set(&ife_ctx->cdm_done, 1);
@@ -6914,7 +6938,11 @@ static int cam_ife_mgr_restart_hw(void *start_hw_args)
 
 	CAM_DBG(CAM_ISP, "START CSID HW ... in ctx id:%d", ctx->ctx_index);
 	/* Start the IFE CSID HW devices */
-	cam_ife_mgr_csid_start_hw(ctx, CAM_IFE_PIX_PATH_RES_MAX, false);
+	rc = cam_ife_mgr_csid_start_hw(ctx, CAM_IFE_PIX_PATH_RES_MAX, false);
+	if (rc) {
+		CAM_ERR(CAM_ISP, "Error in starting CSID HW in ctx id:%d", ctx->ctx_index);
+		goto err;
+	}
 
 	/* Start IFE root node: do nothing */
 	CAM_DBG(CAM_ISP, "Exit...(success)");
@@ -7302,8 +7330,10 @@ start_only:
 	CAM_DBG(CAM_ISP, "START CSID HW ... in ctx id:%d",
 		ctx->ctx_index);
 	/* Start the IFE CSID HW devices */
-	cam_ife_mgr_csid_start_hw(ctx, primary_rdi_csid_res,
+	rc = cam_ife_mgr_csid_start_hw(ctx, primary_rdi_csid_res,
 		start_isp->is_internal_start);
+	if (rc)
+		goto err;
 
 	/* Start IFE root node: do nothing */
 	CAM_DBG(CAM_ISP, "Start success for ctx id:%d", ctx->ctx_index);
@@ -7436,6 +7466,7 @@ static int cam_ife_mgr_release_hw(void *hw_mgr_priv,
 	/* clean context */
 	list_del_init(&ctx->list);
 	ctx->cdm_handle = 0;
+	ctx->cdm_hw_idx = -1;
 	ctx->cdm_ops = NULL;
 	ctx->num_reg_dump_buf = 0;
 	ctx->ctx_type = CAM_IFE_CTX_TYPE_NONE;

+ 2 - 0
drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.h

@@ -256,6 +256,7 @@ struct cam_ife_cdm_user_data {
  *                          instance associated with this context.
  * @num_base                number of valid base data in the base array
  * @cdm_handle              cdm hw acquire handle
+ * @cdm_hw_idx:             Physical CDM in use
  * @cdm_ops                 cdm util operation pointer for building
  *                          cdm commands
  * @cdm_cmd                 cdm base and length request pointer
@@ -315,6 +316,7 @@ struct cam_ife_hw_mgr_ctx {
 								CAM_SFE_HW_NUM_MAX];
 	uint32_t                                   num_base;
 	uint32_t                                   cdm_handle;
+	int32_t                                    cdm_hw_idx;
 	struct cam_cdm_utils_ops                  *cdm_ops;
 	struct cam_cdm_bl_request                 *cdm_cmd;
 	enum cam_cdm_id                            cdm_id;

+ 2 - 0
drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_common.h

@@ -338,6 +338,7 @@ struct cam_ife_csid_debug_info {
  * @sfe_en:                 flag to indicate if SFE is enabled
  * @pf_err_detected:        flag to indicate if camnoc has encountered
  *                          error - page fault
+ * @domain_id_security      Flag to determine if target has domain-id based security
  */
 struct cam_ife_csid_hw_flags {
 	bool                  device_enabled;
@@ -353,6 +354,7 @@ struct cam_ife_csid_hw_flags {
 	bool                  rdi_lcr_en;
 	bool                  sfe_en;
 	bool                  pf_err_detected;
+	bool                  domain_id_security;
 };
 
 /*

+ 39 - 2
drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.c

@@ -4066,7 +4066,7 @@ static int cam_ife_csid_ver2_enable_csi2(struct cam_ife_csid_ver2_hw *csid_hw)
 	const struct cam_ife_csid_csi2_rx_reg_info  *csi2_reg;
 	uint32_t val = 0;
 	void __iomem *mem_base;
-	struct cam_ife_csid_rx_cfg        *rx_cfg;
+	struct cam_ife_csid_rx_cfg          *rx_cfg;
 	int vc_full_width;
 
 	if (csid_hw->flags.rx_enabled)
@@ -4616,6 +4616,32 @@ static void cam_ife_csid_ver2_testbus_config(
 	CAM_DBG(CAM_ISP, "CSID [%u] test_bus_ctrl: 0x%x", csid_hw->hw_intf->hw_idx, val);
 }
 
+static void cam_ife_csid_ver2_send_secure_info(
+	struct cam_csid_hw_start_args *start_args,
+	struct cam_ife_csid_ver2_hw    *csid_hw)
+{
+	struct cam_ife_csid_secure_info        secure_info;
+
+	secure_info.phy_sel = csid_hw->rx_cfg.phy_sel - 1;
+	secure_info.lane_cfg = csid_hw->rx_cfg.lane_cfg;
+	secure_info.cdm_hw_idx_mask = BIT(start_args->cdm_hw_idx);
+	secure_info.vc_mask = 0;
+	secure_info.csid_hw_idx_mask = BIT(csid_hw->hw_intf->hw_idx);
+
+	if (csid_hw->sync_mode == CAM_ISP_HW_SYNC_MASTER)
+		secure_info.csid_hw_idx_mask |= BIT(csid_hw->dual_core_idx);
+
+	CAM_DBG(CAM_ISP,
+		"PHY secure info for CSID[%u], phy_sel: 0x%x, lane_cfg: 0x%x, ife: 0x%x, cdm: 0x%x, vc_mask: 0x%llx",
+		csid_hw->hw_intf->hw_idx, secure_info.phy_sel,
+		secure_info.lane_cfg, secure_info.csid_hw_idx_mask,
+		secure_info.cdm_hw_idx_mask, secure_info.vc_mask);
+
+	/* Issue one call to PHY for dual IFE cases */
+	cam_subdev_notify_message(CAM_CSIPHY_DEVICE_TYPE,
+		CAM_SUBDEV_MESSAGE_DOMAIN_ID_SECURE_PARAMS, (void *)&secure_info);
+}
+
 int cam_ife_csid_ver2_start(void *hw_priv, void *args,
 			uint32_t arg_size)
 {
@@ -4708,6 +4734,15 @@ int cam_ife_csid_ver2_start(void *hw_priv, void *args,
 		}
 	}
 
+	/*
+	 * For targets with domain-id support, hand over relevant parameters
+	 * to phy driver
+	 */
+	if ((csid_hw->sync_mode != CAM_ISP_HW_SYNC_SLAVE) &&
+		start_args->is_secure &&
+		csid_hw->flags.domain_id_security)
+		cam_ife_csid_ver2_send_secure_info(start_args, csid_hw);
+
 	/*
 	 * Configure RUP/AUP/MUP @ streamon for all enabled paths
 	 * For internal recovery - skip this, CDM packet corresponding
@@ -4804,7 +4839,6 @@ int cam_ife_csid_ver2_stop(void *hw_priv,
 		csid_stop->num_res);
 
 	csid_hw->flags.device_enabled = false;
-	csid_hw->flags.rdi_lcr_en = false;
 
 	reset.reset_type = (csid_hw->flags.fatal_err_detected) ? CAM_IFE_CSID_RESET_GLOBAL :
 		CAM_IFE_CSID_RESET_PATH;
@@ -6191,6 +6225,9 @@ int cam_ife_csid_hw_ver2_init(struct cam_hw_intf *hw_intf,
 		CAM_CPAS_HW_IDX_ANY, NULL))
 		csid_hw->flags.binning_enabled = true;
 
+	if (cam_cpas_query_domain_id_security_support())
+		csid_hw->flags.domain_id_security = true;
+
 	csid_hw->hw_intf->hw_ops.get_hw_caps   = cam_ife_csid_ver2_get_hw_caps;
 	csid_hw->hw_intf->hw_ops.init          = cam_ife_csid_ver2_init_hw;
 	csid_hw->hw_intf->hw_ops.deinit        = cam_ife_csid_ver2_deinit_hw;

+ 27 - 0
drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.h

@@ -529,6 +529,33 @@ struct cam_ife_csid_ver2_common_reg_info {
 	uint32_t decode_format_payload_only;
 };
 
+/**
+ * struct cam_ife_csid_secure_info: Contains all relevant info to be
+ *                                  programmed for targets supporting
+ *                                  this feature
+ * @phy_sel:          Intermediate value for this mask. CSID passes
+ *                    phy_sel.This variable's position at the top is to
+ *                    be left unchanged, to have it be used correctly
+ *                    in the cam_subdev_notify_message callback for
+ *                    csiphy
+ * @lane_cfg:         This value is similar to lane_assign in the PHY
+ *                    driver, and is used to identify the particular
+ *                    PHY instance with which this IFE session is
+ *                    connected to.
+ * @vc_mask:          Virtual channel masks (Unused for mobile usecase)
+ * @csid_hw_idx_mask: Bit position denoting CSID(s) in use for secure
+ *                    session
+ * @cdm_hw_idx_mask:  Bit position denoting CDM in use for secure
+ *                    session
+ */
+struct cam_ife_csid_secure_info {
+	uint32_t phy_sel;
+	uint32_t lane_cfg;
+	uint64_t vc_mask;
+	uint32_t csid_hw_idx_mask;
+	uint32_t cdm_hw_idx_mask;
+};
+
 struct cam_ife_csid_ver2_reg_info {
 	struct cam_irq_controller_reg_info               *top_irq_reg_info;
 	struct cam_irq_controller_reg_info               *rx_irq_reg_info;

+ 13 - 0
drivers/cam_isp/isp_hw_mgr/isp_hw/include/cam_ife_csid_hw_intf.h

@@ -286,9 +286,22 @@ struct cam_csid_hw_stop_args {
 	uint32_t                                  num_res;
 };
 
+/**
+ * struct cam_csid_hw_start_args - Relevant info to pass from ife_hw_mgr layer
+ *                                 to start various resource nodes.
+ *
+ * @node_res:           Resource pointer array (cid or CSID)
+ * @num_res:            Number of resources in node_res
+ * @cdm_hw_idx:         Physical CDM in use together with these resources
+ * @is_secure:          If these resources are run in secure session
+ * @is_internal_start:  Start triggered internally for reset & recovery
+ *
+ */
 struct cam_csid_hw_start_args {
 	struct cam_isp_resource_node            **node_res;
 	uint32_t                                  num_res;
+	uint32_t                                  cdm_hw_idx;
+	bool                                      is_secure;
 	bool                                      is_internal_start;
 };
 

+ 1 - 0
drivers/cam_req_mgr/cam_subdev.h

@@ -20,6 +20,7 @@
 enum cam_subdev_message_type_t {
 	CAM_SUBDEV_MESSAGE_REG_DUMP = 0x1,
 	CAM_SUBDEV_MESSAGE_APPLY_CSIPHY_AUX,
+	CAM_SUBDEV_MESSAGE_DOMAIN_ID_SECURE_PARAMS,
 };
 
 /* Enum for close sequence priority */

+ 32 - 6
drivers/cam_sensor_module/cam_csiphy/cam_csiphy_core.c

@@ -1212,6 +1212,32 @@ static int __cam_csiphy_prgm_bist_reg(struct csiphy_device *csiphy_dev, bool is_
 	return 0;
 }
 
+static int cam_csiphy_program_secure_mode(struct csiphy_device *csiphy_dev,
+	bool protect, int32_t offset)
+{
+	int rc = 0;
+
+	if (!csiphy_dev->domain_id_security)
+		rc = cam_csiphy_notify_secure_mode(csiphy_dev, protect, offset);
+
+	 /* Else a new scm call here */
+	else {
+		if (protect && !csiphy_dev->csiphy_info[offset].secure_info_updated) {
+			CAM_ERR(CAM_CSIPHY, "Secure info not updated prior to stream on");
+			return -EINVAL;
+		}
+
+		csiphy_dev->csiphy_info[offset].secure_info.protect = protect;
+		CAM_DBG(CAM_CSIPHY, "To call new scm, protect: %d, offset: %d",
+			protect, offset);
+
+		if (!protect)
+			csiphy_dev->csiphy_info[offset].secure_info.protect = false;
+	}
+
+	return rc;
+}
+
 int32_t cam_csiphy_config_dev(struct csiphy_device *csiphy_dev,
 	int32_t dev_handle, uint8_t datarate_variant_idx)
 {
@@ -1391,7 +1417,7 @@ void cam_csiphy_shutdown(struct csiphy_device *csiphy_dev)
 
 		for (i = 0; i < csiphy_dev->acquire_count; i++) {
 			if (csiphy_dev->csiphy_info[i].secure_mode)
-				cam_csiphy_notify_secure_mode(
+				cam_csiphy_program_secure_mode(
 					csiphy_dev,
 					CAM_SECURE_MODE_NON_SECURE, i);
 
@@ -2141,7 +2167,7 @@ int32_t cam_csiphy_core_cfg(void *phy_dev,
 
 		if (--csiphy_dev->start_dev_count) {
 			if (csiphy_dev->csiphy_info[offset].secure_mode)
-				cam_csiphy_notify_secure_mode(
+				cam_csiphy_program_secure_mode(
 					csiphy_dev,
 					CAM_SECURE_MODE_NON_SECURE, offset);
 
@@ -2165,7 +2191,7 @@ int32_t cam_csiphy_core_cfg(void *phy_dev,
 		}
 
 		if (csiphy_dev->csiphy_info[offset].secure_mode)
-			cam_csiphy_notify_secure_mode(
+			cam_csiphy_program_secure_mode(
 				csiphy_dev,
 				CAM_SECURE_MODE_NON_SECURE, offset);
 
@@ -2237,7 +2263,7 @@ int32_t cam_csiphy_core_cfg(void *phy_dev,
 		}
 
 		if (csiphy_dev->csiphy_info[offset].secure_mode)
-			cam_csiphy_notify_secure_mode(
+			cam_csiphy_program_secure_mode(
 				csiphy_dev,
 				CAM_SECURE_MODE_NON_SECURE, offset);
 
@@ -2362,7 +2388,7 @@ int32_t cam_csiphy_core_cfg(void *phy_dev,
 					goto release_mutex;
 				}
 
-				rc = cam_csiphy_notify_secure_mode(csiphy_dev,
+				rc = cam_csiphy_program_secure_mode(csiphy_dev,
 					CAM_SECURE_MODE_SECURE, offset);
 				if (rc < 0) {
 					csiphy_dev->csiphy_info[offset]
@@ -2428,7 +2454,7 @@ int32_t cam_csiphy_core_cfg(void *phy_dev,
 				goto cpas_stop;
 			}
 
-			rc = cam_csiphy_notify_secure_mode(
+			rc = cam_csiphy_program_secure_mode(
 				csiphy_dev,
 				CAM_SECURE_MODE_SECURE, offset);
 			if (rc < 0) {

+ 109 - 0
drivers/cam_sensor_module/cam_csiphy/cam_csiphy_dev.c

@@ -28,6 +28,107 @@ static inline void cam_csiphy_trigger_reg_dump(struct csiphy_device *csiphy_dev)
 	}
 }
 
+int cam_csiphy_format_secure_phy_lane_info(
+	struct csiphy_device *csiphy_dev, int offset)
+{
+	struct cam_csiphy_tz_secure_info *tz_secure_info;
+	struct cam_csiphy_param *param;
+
+	if (!csiphy_dev) {
+		CAM_ERR(CAM_CSIPHY, "Invalid param, csiphy_dev: %s",
+			CAM_IS_NULL_TO_STR(csiphy_dev));
+		return -EINVAL;
+	}
+
+	if (offset >= CSIPHY_MAX_INSTANCES_PER_PHY) {
+		CAM_ERR(CAM_CSIPHY, "Invalid CSIPHY param offset: %d",
+			offset);
+		return -EINVAL;
+	}
+
+	param = &csiphy_dev->csiphy_info[offset];
+	tz_secure_info = &param->secure_info;
+
+	if (param->csiphy_3phase) {
+		if (param->lane_enable & CPHY_LANE_0)
+			tz_secure_info->phy_lane_sel_mask |= LANE_0_SEL;
+		if (param->lane_enable & CPHY_LANE_1)
+			tz_secure_info->phy_lane_sel_mask |= LANE_1_SEL;
+		if (param->lane_enable & CPHY_LANE_2)
+			tz_secure_info->phy_lane_sel_mask |= LANE_2_SEL;
+		tz_secure_info->phy_lane_sel_mask <<= CPHY_LANE_SELECTION_SHIFT;
+	} else {
+		if (param->lane_enable & DPHY_LANE_0)
+			tz_secure_info->phy_lane_sel_mask |= LANE_0_SEL;
+		if (param->lane_enable & DPHY_LANE_1)
+			tz_secure_info->phy_lane_sel_mask |= LANE_1_SEL;
+		if (param->lane_enable & DPHY_LANE_2)
+			tz_secure_info->phy_lane_sel_mask |= LANE_2_SEL;
+		if (param->lane_enable & DPHY_LANE_3)
+			tz_secure_info->phy_lane_sel_mask |= LANE_3_SEL;
+		tz_secure_info->phy_lane_sel_mask <<= DPHY_LANE_SELECTION_SHIFT;
+	}
+	if (csiphy_dev->soc_info.index > MAX_SUPPORTED_PHY_IDX) {
+		CAM_ERR(CAM_CSIPHY, "Invalid PHY index: %u",
+			csiphy_dev->soc_info.index);
+			return -EINVAL;
+	}
+	tz_secure_info->phy_lane_sel_mask |= BIT(csiphy_dev->soc_info.index);
+
+	CAM_DBG(CAM_CSIPHY, "Formatted PHY[%u] phy_lane_sel_mask: 0x%llx",
+		csiphy_dev->soc_info.index,
+		tz_secure_info->phy_lane_sel_mask);
+
+	return 0;
+
+}
+
+static void cam_csiphy_populate_secure_info(
+	struct csiphy_device *csiphy_dev, void *data)
+{
+	int i;
+	struct cam_csiphy_secure_info *secure_info =
+		(struct cam_csiphy_secure_info *)data;
+	struct cam_csiphy_param *param;
+	struct cam_csiphy_tz_secure_info *tz_secure_info;
+
+	for (i = 0; i < CSIPHY_MAX_INSTANCES_PER_PHY; i++) {
+		param = &csiphy_dev->csiphy_info[i];
+
+		if (param->secure_mode &&
+			param->lane_assign == secure_info->lane_assign) {
+			tz_secure_info = &param->secure_info;
+
+			tz_secure_info->cdm_hw_idx_mask = secure_info->cdm_hw_idx_mask;
+			tz_secure_info->csid_hw_idx_mask = secure_info->csid_hw_idx_mask;
+			tz_secure_info->vc_mask = secure_info->vc_mask;
+			tz_secure_info->phy_lane_sel_mask = 0;
+
+			if (!cam_csiphy_format_secure_phy_lane_info(csiphy_dev, i)) {
+				param->secure_info_updated =  true;
+
+				CAM_DBG(CAM_CSIPHY,
+					"PHY[%d] secure info, phy_lane_mask: 0x%llx, ife: 0x%x, cdm: 0x%x, vc_mask: 0x%llx",
+					csiphy_dev->soc_info.index,
+					tz_secure_info->phy_lane_sel_mask,
+					tz_secure_info->csid_hw_idx_mask,
+					tz_secure_info->cdm_hw_idx_mask,
+					tz_secure_info->vc_mask);
+			} else
+				CAM_ERR(CAM_CSIPHY,
+					"Error in formatting PHY[%u] phy_lane_sel_mask: 0x%llx",
+					csiphy_dev->soc_info.index,
+					tz_secure_info->phy_lane_sel_mask);
+
+			break;
+		}
+	}
+
+	if (i == CSIPHY_MAX_INSTANCES_PER_PHY)
+		CAM_ERR(CAM_CSIPHY, "No matching secure PHY for a session");
+
+}
+
 static void cam_csiphy_subdev_handle_message(struct v4l2_subdev *sd,
 	enum cam_subdev_message_type_t message_type, void *data)
 {
@@ -64,6 +165,11 @@ static void cam_csiphy_subdev_handle_message(struct v4l2_subdev *sd,
 		}
 		break;
 	}
+	case CAM_SUBDEV_MESSAGE_DOMAIN_ID_SECURE_PARAMS: {
+		cam_csiphy_populate_secure_info(csiphy_dev, data);
+
+		break;
+	}
 	default:
 		break;
 	}
@@ -281,6 +387,9 @@ static int cam_csiphy_component_bind(struct device *dev,
 		goto csiphy_no_resource;
 	}
 
+	if (cam_cpas_query_domain_id_security_support())
+		new_csiphy_dev->domain_id_security = true;
+
 	new_csiphy_dev->v4l2_dev_str.internal_ops =
 		&csiphy_subdev_intern_ops;
 	new_csiphy_dev->v4l2_dev_str.ops =

+ 72 - 10
drivers/cam_sensor_module/cam_csiphy/cam_csiphy_dev.h

@@ -70,6 +70,15 @@
 #define DPHY_LANE_3    BIT(6)
 #define DPHY_CLK_LN    BIT(7)
 
+/* Lane info packing for scm call */
+#define LANE_0_SEL                   BIT(0)
+#define LANE_1_SEL                   BIT(1)
+#define LANE_2_SEL                   BIT(2)
+#define LANE_3_SEL                   BIT(3)
+#define CPHY_LANE_SELECTION_SHIFT    8
+#define DPHY_LANE_SELECTION_SHIFT    16
+#define MAX_SUPPORTED_PHY_IDX        7
+
 /* PRBS Pattern Macros */
 #define PREAMBLE_PATTERN_SET_CHECKER    BIT(4)
 #define PREAMBLE_PATTERN_BIST_DONE      BIT(0)
@@ -91,6 +100,51 @@ enum cam_csiphy_common_reg_program {
 	CAM_CSIPHY_PRGM_INDVDL,
 };
 
+/**
+ * struct cam_csiphy_secure_info
+ *
+ * This is an internal struct that is a reflection of the one
+ * passed over from csid
+ *
+ * @phy_lane_sel_mask: This value to be filled completely by csiphy
+ * @lane_assign:       Lane_cfg value sent over from csid is
+ *                     equivalent to lane_assign here
+ * @vc_mask:           Virtual channel masks (Unused for mobile usecase)
+ * @csid_hw_idx_mask:  Bit position denoting CSID(s) in use for secure
+ *                     session
+ * @cdm_hw_idx_mask:   Bit position denoting CDM in use for secure
+ *                     session
+ */
+struct cam_csiphy_secure_info {
+	uint32_t phy_lane_sel_mask;
+	uint32_t lane_assign;
+	uint64_t vc_mask;
+	uint32_t csid_hw_idx_mask;
+	uint32_t cdm_hw_idx_mask;
+};
+
+/**
+ * struct cam_csiphy_tz_secure_info
+ *
+ * This is the struct containing all the necessary values
+ * for scm programming of domain id
+ *
+ * @phy_lane_sel_mask: This value to be filled completely by csiphy
+ * @csid_hw_idx_mask:  Bit position denoting CSID(s) in use for secure
+ *                     session
+ * @cdm_hw_idx_mask:   Bit position denoting CDM in use for secure
+ *                     session
+ * @vc_mask:           VC mask (unused in mobile case)
+ * @protect:           To protect or reset previously protected lanes
+ */
+struct cam_csiphy_tz_secure_info {
+	uint64_t phy_lane_sel_mask;
+	uint32_t csid_hw_idx_mask;
+	uint32_t cdm_hw_idx_mask;
+	uint64_t vc_mask;
+	bool     protect;
+};
+
 /**
  * struct cam_csiphy_aon_sel_params_t
  * @aon_cam_sel_offset : AON Cam Select Register offset in cpas top
@@ -276,18 +330,24 @@ struct csiphy_ctrl_t {
  * @mipi_flags                 :  MIPI phy flags
  * @csiphy_cpas_cp_reg_mask    :  CP reg mask for phy instance
  * @hdl_data                   :  CSIPHY handle table
+ * @secure_info                :  All domain-id security related information packed in proper
+ *                                format for scm call
+ * @secure_info_updated        :  If all information in the secure_info struct above
+ *                                is passed and formatted properly from CSID driver
  */
 struct cam_csiphy_param {
-	uint16_t                   lane_assign;
-	uint8_t                    lane_cnt;
-	uint8_t                    secure_mode;
-	uint32_t                   lane_enable;
-	uint64_t                   settle_time;
-	uint64_t                   data_rate;
-	int                        csiphy_3phase;
-	uint16_t                   mipi_flags;
-	uint64_t                   csiphy_cpas_cp_reg_mask;
-	struct csiphy_hdl_tbl      hdl_data;
+	uint16_t                         lane_assign;
+	uint8_t                          lane_cnt;
+	uint8_t                          secure_mode;
+	uint32_t                         lane_enable;
+	uint64_t                         settle_time;
+	uint64_t                         data_rate;
+	int                              csiphy_3phase;
+	uint16_t                         mipi_flags;
+	uint64_t                         csiphy_cpas_cp_reg_mask;
+	struct csiphy_hdl_tbl            hdl_data;
+	struct cam_csiphy_tz_secure_info secure_info;
+	bool                             secure_info_updated;
 };
 
 struct csiphy_work_queue {
@@ -361,6 +421,7 @@ struct cam_csiphy_dev_aux_setting_params {
  * @en_lane_status_reg_dump    : Debugfs flag to enable cphy/dphy lane status dump
  * @en_full_phy_reg_dump       : Debugfs flag to enable the dump for all the Phy registers
  * @skip_aux_settings          : Debugfs flag to ignore calls to update aux settings
+ * @domain_id_security         : Flag to determine if target has domain-id based security
  * @preamble_enable            : To enable preamble pattern
  */
 struct csiphy_device {
@@ -399,6 +460,7 @@ struct csiphy_device {
 	bool                                     en_lane_status_reg_dump;
 	bool                                     en_full_phy_reg_dump;
 	bool                                     skip_aux_settings;
+	bool                                     domain_id_security;
 	uint16_t                                 preamble_enable;
 };