diff --git a/drivers/cam_cpas/cpas_top/cam_cpastop_hw.c b/drivers/cam_cpas/cpas_top/cam_cpastop_hw.c index f91179b5aa..9068dd3ebe 100644 --- a/drivers/cam_cpas/cpas_top/cam_cpastop_hw.c +++ b/drivers/cam_cpas/cpas_top/cam_cpastop_hw.c @@ -7,8 +7,7 @@ #include #include -#include - +#include "cam_compat.h" #include "cam_cpas_hw_intf.h" #include "cam_cpas_hw.h" #include "cam_cpastop_hw.h" @@ -519,7 +518,7 @@ done: static int cam_cpastop_poweron(struct cam_hw_info *cpas_hw) { - int i, reg_val; + int i; struct cam_cpas_hw_errata_wa_list *errata_wa_list = camnoc_info->errata_wa_list; struct cam_cpas_hw_errata_wa *errata_wa = @@ -546,9 +545,7 @@ static int cam_cpastop_poweron(struct cam_hw_info *cpas_hw) } if (errata_wa->enable) { - reg_val = scm_io_read(errata_wa->data.reg_info.offset); - reg_val |= errata_wa->data.reg_info.value; - scm_io_write(errata_wa->data.reg_info.offset, reg_val); + cam_cpastop_scm_write(errata_wa); } return 0; diff --git a/drivers/cam_cust/cam_custom_hw_mgr/cam_custom_hw_mgr.c b/drivers/cam_cust/cam_custom_hw_mgr/cam_custom_hw_mgr.c index afd08fb990..78226a5f32 100644 --- a/drivers/cam_cust/cam_custom_hw_mgr/cam_custom_hw_mgr.c +++ b/drivers/cam_cust/cam_custom_hw_mgr/cam_custom_hw_mgr.c @@ -8,10 +8,10 @@ #include #include -#include #include #include +#include "cam_compat.h" #include "cam_sync_api.h" #include "cam_smmu_api.h" #include "cam_req_mgr_workq.h" 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 b02c7adf6f..679c235711 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 @@ -8,9 +8,9 @@ #include #include -#include #include +#include "cam_compat.h" #include "cam_smmu_api.h" #include "cam_req_mgr_workq.h" #include "cam_isp_hw_mgr_intf.h" @@ -28,8 +28,6 @@ #define CAM_IFE_HW_ENTRIES_MAX 20 -#define TZ_SVC_SMMU_PROGRAM 0x15 -#define TZ_SAFE_SYSCALL_ID 0x3 #define CAM_IFE_SAFE_DISABLE 0 #define CAM_IFE_SAFE_ENABLE 1 #define SMMU_SE_IFE 0 @@ -172,38 +170,6 @@ static int cam_ife_mgr_handle_reg_dump(struct cam_ife_hw_mgr_ctx *ctx, return rc; } -static int cam_ife_notify_safe_lut_scm(bool safe_trigger) -{ - uint32_t camera_hw_version, rc = 0; - struct scm_desc desc = {0}; - - rc = cam_cpas_get_cpas_hw_version(&camera_hw_version); - if (!rc) { - switch (camera_hw_version) { - case CAM_CPAS_TITAN_170_V100: - case CAM_CPAS_TITAN_170_V110: - case CAM_CPAS_TITAN_175_V100: - - desc.arginfo = SCM_ARGS(2, SCM_VAL, SCM_VAL); - desc.args[0] = SMMU_SE_IFE; - desc.args[1] = safe_trigger; - - CAM_DBG(CAM_ISP, "Safe scm call %d", safe_trigger); - if (scm_call2(SCM_SIP_FNID(TZ_SVC_SMMU_PROGRAM, - TZ_SAFE_SYSCALL_ID), &desc)) { - CAM_ERR(CAM_ISP, - "scm call to Enable Safe failed"); - rc = -EINVAL; - } - break; - default: - break; - } - } - - return rc; -} - static int cam_ife_mgr_get_hw_caps(void *hw_mgr_priv, void *hw_caps_args) { diff --git a/drivers/cam_req_mgr/cam_mem_mgr.c b/drivers/cam_req_mgr/cam_mem_mgr.c index 559a1c42b0..f6eec4446c 100644 --- a/drivers/cam_req_mgr/cam_mem_mgr.c +++ b/drivers/cam_req_mgr/cam_mem_mgr.c @@ -10,10 +10,6 @@ #include #include -#if KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE -#include -#endif - #include "cam_compat.h" #include "cam_req_mgr_util.h" #include "cam_mem_mgr.h" diff --git a/drivers/cam_sensor_module/cam_csiphy/cam_csiphy_core.c b/drivers/cam_sensor_module/cam_csiphy/cam_csiphy_core.c index fdab05b0e3..ec8dd1ae68 100644 --- a/drivers/cam_sensor_module/cam_csiphy/cam_csiphy_core.c +++ b/drivers/cam_sensor_module/cam_csiphy/cam_csiphy_core.c @@ -4,21 +4,17 @@ */ #include + +#include + +#include "cam_compat.h" #include "cam_csiphy_core.h" #include "cam_csiphy_dev.h" #include "cam_csiphy_soc.h" #include "cam_common_util.h" #include "cam_packet_util.h" - -#include - -#include -#include -#include - -#define SCM_SVC_CAMERASS 0x18 -#define SECURE_SYSCALL_ID 0x6 -#define SECURE_SYSCALL_ID_2 0x7 +#include "cam_mem_mgr.h" +#include "cam_cpas_api.h" #define LANE_MASK_2PH 0x1F #define LANE_MASK_3PH 0x7 @@ -26,29 +22,6 @@ static int csiphy_dump; module_param(csiphy_dump, int, 0644); -static int cam_csiphy_notify_secure_mode(struct csiphy_device *csiphy_dev, - bool protect, int32_t offset) -{ - struct scm_desc desc = {0}; - - if (offset >= CSIPHY_MAX_INSTANCES) { - CAM_ERR(CAM_CSIPHY, "Invalid CSIPHY offset"); - return -EINVAL; - } - - desc.arginfo = SCM_ARGS(2, SCM_VAL, SCM_VAL); - desc.args[0] = protect; - desc.args[1] = csiphy_dev->csiphy_cpas_cp_reg_mask[offset]; - - if (scm_call2(SCM_SIP_FNID(SCM_SVC_CAMERASS, SECURE_SYSCALL_ID_2), - &desc)) { - CAM_ERR(CAM_CSIPHY, "scm call to hypervisor failed"); - return -EINVAL; - } - - return 0; -} - int32_t cam_csiphy_get_instance_offset( struct csiphy_device *csiphy_dev, int32_t dev_handle) diff --git a/drivers/cam_smmu/cam_smmu_api.c b/drivers/cam_smmu/cam_smmu_api.c index 269982f444..3043bee219 100644 --- a/drivers/cam_smmu/cam_smmu_api.c +++ b/drivers/cam_smmu/cam_smmu_api.c @@ -15,8 +15,6 @@ #include #include #include - -#include #include #include diff --git a/drivers/cam_utils/cam_compat.c b/drivers/cam_utils/cam_compat.c index 72ec49b5b6..aa3c02bafb 100644 --- a/drivers/cam_utils/cam_compat.c +++ b/drivers/cam_utils/cam_compat.c @@ -8,8 +8,9 @@ #include "cam_compat.h" #include "cam_debug_util.h" +#include "cam_cpas_api.h" -#if KERNEL_VERSION(5, 4, 0) >= LINUX_VERSION_CODE +#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE int cam_reserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length) { int rc = 0; @@ -47,6 +48,54 @@ void cam_unreserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length) { iounmap(icp_fw->fw_kva); } + +int cam_ife_notify_safe_lut_scm(bool safe_trigger) +{ + const uint32_t smmu_se_ife = 0; + uint32_t camera_hw_version, rc = 0; + + rc = cam_cpas_get_cpas_hw_version(&camera_hw_version); + if (!rc && qcom_scm_smmu_notify_secure_lut(smmu_se_ife, safe_trigger)) { + switch (camera_hw_version) { + case CAM_CPAS_TITAN_170_V100: + case CAM_CPAS_TITAN_170_V110: + case CAM_CPAS_TITAN_175_V100: + CAM_ERR(CAM_ISP, "scm call to enable safe failed"); + rc = -EINVAL; + break; + default: + break; + } + } + + return rc; +} + +int cam_csiphy_notify_secure_mode(struct csiphy_device *csiphy_dev, + bool protect, int32_t offset) +{ + int rc = 0; + + if (offset >= CSIPHY_MAX_INSTANCES) { + CAM_ERR(CAM_CSIPHY, "Invalid CSIPHY offset"); + rc = -EINVAL; + } else if (qcom_scm_camera_protect_phy_lanes(protect, + csiphy_dev->csiphy_cpas_cp_reg_mask[offset])) { + CAM_ERR(CAM_CSIPHY, "SCM call to hypervisor failed"); + rc = -EINVAL; + } + + return 0; +} + +void cam_cpastop_scm_write(struct cam_cpas_hw_errata_wa *errata_wa) +{ + int reg_val; + + qcom_scm_io_readl(errata_wa->data.reg_info.offset, ®_val); + reg_val |= errata_wa->data.reg_info.value; + qcom_scm_io_writel(errata_wa->data.reg_info.offset, reg_val); +} #else int cam_reserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length) { @@ -68,4 +117,61 @@ void cam_unreserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length) dma_free_coherent(icp_fw->fw_dev, fw_length, icp_fw->fw_kva, icp_fw->fw_hdl); } + +int cam_ife_notify_safe_lut_scm(bool safe_trigger) +{ + const uint32_t smmu_se_ife = 0; + uint32_t camera_hw_version, rc = 0; + struct scm_desc description = { + .arginfo = SCM_ARGS(2, SCM_VAL, SCM_VAL), + .args[0] = smmu_se_ife, + .args[1] = safe_trigger, + }; + + rc = cam_cpas_get_cpas_hw_version(&camera_hw_version); + if (!rc && scm_call2(SCM_SIP_FNID(0x15, 0x3), &description)) { + switch (camera_hw_version) { + case CAM_CPAS_TITAN_170_V100: + case CAM_CPAS_TITAN_170_V110: + case CAM_CPAS_TITAN_175_V100: + CAM_ERR(CAM_ISP, "scm call to enable safe failed"); + rc = -EINVAL; + break; + default: + break; + } + } + + return rc; +} + +int cam_csiphy_notify_secure_mode(struct csiphy_device *csiphy_dev, + bool protect, int32_t offset) +{ + int rc = 0; + struct scm_desc description = { + .arginfo = SCM_ARGS(2, SCM_VAL, SCM_VAL), + .args[0] = protect, + .args[1] = csiphy_dev->csiphy_cpas_cp_reg_mask[offset], + }; + + if (offset >= CSIPHY_MAX_INSTANCES) { + CAM_ERR(CAM_CSIPHY, "Invalid CSIPHY offset"); + rc = -EINVAL; + } else if (scm_call2(SCM_SIP_FNID(0x18, 0x7), &description)) { + CAM_ERR(CAM_CSIPHY, "SCM call to hypervisor failed"); + rc = -EINVAL; + } + + return 0; +} + +void cam_cpastop_scm_write(struct cam_cpas_hw_errata_wa *errata_wa) +{ + int reg_val; + + reg_val = scm_io_read(errata_wa->data.reg_info.offset); + reg_val |= errata_wa->data.reg_info.value; + scm_io_write(errata_wa->data.reg_info.offset, reg_val); +} #endif diff --git a/drivers/cam_utils/cam_compat.h b/drivers/cam_utils/cam_compat.h index caf0ac8e15..3e7bec620c 100644 --- a/drivers/cam_utils/cam_compat.h +++ b/drivers/cam_utils/cam_compat.h @@ -8,15 +8,20 @@ #include -#if KERNEL_VERSION(5, 4, 0) >= LINUX_VERSION_CODE +#include "cam_csiphy_dev.h" +#include "cam_cpastop_hw.h" + +#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE #include #include +#include #else #include #include +#include #endif @@ -28,5 +33,9 @@ struct cam_fw_alloc_info { int cam_reserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length); void cam_unreserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length); +void cam_cpastop_scm_write(struct cam_cpas_hw_errata_wa *errata_wa); +int cam_ife_notify_safe_lut_scm(bool safe_trigger); +int cam_csiphy_notify_secure_mode(struct csiphy_device *csiphy_dev, + bool protect, int32_t offset); #endif /* _CAM_COMPAT_H_ */