Merge "msm: camera: Notify TZ App about changes of the HW security mode"
This commit is contained in:
commit
8ae6b25770
5 changed files with 627 additions and 377 deletions
|
@ -1,2 +1,3 @@
|
|||
ccflags-y += -Idrivers/media/platform/msm/camera_v2/
|
||||
obj-$(CONFIG_MSMB_CAMERA) += msm_camera_io_util.o cam_smmu_api.o cam_hw_ops.o cam_soc_api.o
|
||||
ccflags-y += -Idrivers/misc/
|
||||
obj-$(CONFIG_MSMB_CAMERA) += msm_camera_io_util.o cam_smmu_api.o cam_hw_ops.o cam_soc_api.o msm_camera_tz_util.o
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <linux/workqueue.h>
|
||||
#include <soc/qcom/scm.h>
|
||||
#include <soc/qcom/secure_buffer.h>
|
||||
#include <msm_camera_tz_util.h>
|
||||
#include "cam_smmu_api.h"
|
||||
|
||||
#define SCRATCH_ALLOC_START SZ_128K
|
||||
|
@ -883,16 +884,26 @@ static int cam_smmu_attach_sec_cpp(int idx)
|
|||
* all cpp sids are shared in SCM call. so no need of
|
||||
* attach again.
|
||||
*/
|
||||
|
||||
if (cam_smmu_send_syscall_cpp_intf(VMID_CP_CAMERA, idx)) {
|
||||
pr_err("error: syscall failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
msm_camera_tz_set_mode(MSM_CAMERA_TZ_MODE_SECURE,
|
||||
MSM_CAMERA_TZ_HW_BLOCK_CPP);
|
||||
|
||||
iommu_cb_set.cb_info[idx].state = CAM_SMMU_ATTACH;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cam_smmu_detach_sec_cpp(int idx)
|
||||
{
|
||||
msm_camera_tz_set_mode(MSM_CAMERA_TZ_MODE_NON_SECURE,
|
||||
MSM_CAMERA_TZ_HW_BLOCK_CPP);
|
||||
|
||||
iommu_cb_set.cb_info[idx].state = CAM_SMMU_DETACH;
|
||||
|
||||
/*
|
||||
* When exiting secure, do scm call to attach
|
||||
* with CPP SID in NS mode.
|
||||
|
@ -921,11 +932,18 @@ static int cam_smmu_attach_sec_vfe_ns_stats(int idx)
|
|||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
msm_camera_tz_set_mode(MSM_CAMERA_TZ_MODE_SECURE,
|
||||
MSM_CAMERA_TZ_HW_BLOCK_ISP);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cam_smmu_detach_sec_vfe_ns_stats(int idx)
|
||||
{
|
||||
msm_camera_tz_set_mode(MSM_CAMERA_TZ_MODE_NON_SECURE,
|
||||
MSM_CAMERA_TZ_HW_BLOCK_ISP);
|
||||
|
||||
/*
|
||||
*While exiting from secure mode for secure pixel and non-secure stats,
|
||||
*localizing detach/scm of non-secure SID's to detach secure
|
||||
|
|
351
drivers/media/platform/msm/camera_v2/common/msm_camera_tz_util.c
Normal file
351
drivers/media/platform/msm/camera_v2/common/msm_camera_tz_util.c
Normal file
|
@ -0,0 +1,351 @@
|
|||
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
* only version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ktime.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <soc/qcom/camera2.h>
|
||||
#include "qseecom_kernel.h"
|
||||
#include "msm_camera_tz_util.h"
|
||||
|
||||
#define EMPTY_QSEECOM_HANDLE NULL
|
||||
#define QSEECOM_SBUFF_SIZE SZ_128K
|
||||
|
||||
#define MSM_CAMERA_TZ_UTIL_VERBOSE
|
||||
|
||||
#define MSM_CAMERA_TZ_BOOT_PROTECTED (false)
|
||||
|
||||
/* Update version major number in case the HLOS-TA interface is changed*/
|
||||
#define TA_IF_VERSION_MAJ 1
|
||||
#define TA_IF_VERSION_MIN 2
|
||||
|
||||
#undef CDBG
|
||||
#ifdef MSM_CAMERA_TZ_UTIL_VERBOSE
|
||||
#define CDBG(fmt, args...) \
|
||||
pr_info(CONFIG_MSM_SEC_CCI_TA_NAME "::%s:%d - " fmt,\
|
||||
__func__, __LINE__, ##args)
|
||||
#else /* MSM_CAMERA_TZ_UTIL_VERBOSE */
|
||||
#define CDBG(fmt, args...) \
|
||||
pr_debug("%s:%d - " fmt, __func__, __LINE__, ##args)
|
||||
#endif /* MSM_CAMERA_TZ_UTIL_VERBOSE */
|
||||
|
||||
#pragma pack(push, msm_camera_tz_util, 1)
|
||||
|
||||
/* MSM_CAMERA_TZ_CMD_GET_IF_VERSION */
|
||||
#define msm_camera_tz_i2c_get_if_version_req_t msm_camera_tz_generic_req_t
|
||||
|
||||
struct msm_camera_tz_i2c_get_if_version_rsp_t {
|
||||
enum msm_camera_tz_status_t rc;
|
||||
uint32_t if_version_maj;
|
||||
uint32_t if_version_min;
|
||||
};
|
||||
|
||||
/* MSM_CAMERA_TZ_CMD_SET_MODE */
|
||||
struct msm_camera_tz_set_mode_req_t {
|
||||
enum msm_camera_tz_cmd_id_t cmd_id;
|
||||
uint32_t mode;
|
||||
uint32_t hw_block;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_set_mode_rsp_t msm_camera_tz_generic_rsp_t
|
||||
|
||||
#pragma pack(pop, msm_camera_tz_util)
|
||||
|
||||
/* TA communication control structure */
|
||||
struct msm_camera_tz_ctrl_t {
|
||||
uint32_t ta_enabled;
|
||||
struct qseecom_handle *ta_qseecom_handle;
|
||||
const char *ta_name;
|
||||
uint32_t secure_hw_blocks;
|
||||
};
|
||||
|
||||
static struct msm_camera_tz_ctrl_t msm_camera_tz_ctrl = {
|
||||
0, NULL, CONFIG_MSM_CAMERA_TZ_TA_NAME, 0
|
||||
};
|
||||
|
||||
static DEFINE_MUTEX(msm_camera_tz_util_lock);
|
||||
|
||||
struct qseecom_handle *msm_camera_tz_get_ta_handle()
|
||||
{
|
||||
return msm_camera_tz_ctrl.ta_qseecom_handle;
|
||||
}
|
||||
|
||||
void msm_camera_tz_lock(void)
|
||||
{
|
||||
mutex_lock(&msm_camera_tz_util_lock);
|
||||
}
|
||||
|
||||
void msm_camera_tz_unlock(void)
|
||||
{
|
||||
mutex_unlock(&msm_camera_tz_util_lock);
|
||||
}
|
||||
|
||||
int32_t get_cmd_rsp_buffers(
|
||||
struct qseecom_handle *ta_qseecom_handle,
|
||||
void **cmd, int *cmd_len,
|
||||
void **rsp, int *rsp_len)
|
||||
{
|
||||
if ((ta_qseecom_handle == NULL) ||
|
||||
(cmd == NULL) || (cmd_len == NULL) ||
|
||||
(rsp == NULL) || (rsp_len == NULL)) {
|
||||
pr_err("%s:%d - Bad parameters\n",
|
||||
__func__, __LINE__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (*cmd_len & QSEECOM_ALIGN_MASK)
|
||||
*cmd_len = QSEECOM_ALIGN(*cmd_len);
|
||||
|
||||
if (*rsp_len & QSEECOM_ALIGN_MASK)
|
||||
*rsp_len = QSEECOM_ALIGN(*rsp_len);
|
||||
|
||||
if ((*rsp_len + *cmd_len) > QSEECOM_SBUFF_SIZE) {
|
||||
pr_err("%s:%d - Shared buffer too small to hold cmd=%d and rsp=%d\n",
|
||||
__func__, __LINE__,
|
||||
*cmd_len, *rsp_len);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*cmd = ta_qseecom_handle->sbuf;
|
||||
*rsp = ta_qseecom_handle->sbuf + *cmd_len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t msm_camera_tz_i2c_ta_get_if_version(
|
||||
struct qseecom_handle *ta_qseecom_handle,
|
||||
uint32_t *if_version_maj,
|
||||
uint32_t *if_version_min)
|
||||
{
|
||||
int32_t cmd_len, rsp_len;
|
||||
struct msm_camera_tz_i2c_get_if_version_req_t *cmd;
|
||||
struct msm_camera_tz_i2c_get_if_version_rsp_t *rsp;
|
||||
int32_t rc = 0;
|
||||
|
||||
CDBG("Enter\n");
|
||||
if ((ta_qseecom_handle == NULL) ||
|
||||
(if_version_maj == NULL) || (if_version_min == NULL)) {
|
||||
pr_err("%s:%d - Bad parameters\n",
|
||||
__func__, __LINE__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cmd_len = sizeof(struct msm_camera_tz_i2c_get_if_version_req_t);
|
||||
rsp_len = sizeof(struct msm_camera_tz_i2c_get_if_version_rsp_t);
|
||||
|
||||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = MSM_CAMERA_TZ_CMD_GET_IF_VERSION;
|
||||
|
||||
rc = qseecom_send_command(ta_qseecom_handle,
|
||||
(void *)cmd, cmd_len, (void *)rsp, rsp_len);
|
||||
|
||||
if (rc < 0) {
|
||||
pr_err("%s:%d - Unable to get if version info, rc=%d\n",
|
||||
__func__, __LINE__,
|
||||
rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rsp->rc < 0) {
|
||||
CDBG("TZ App error, rc=%d\n", rsp->rc);
|
||||
rc = -EFAULT;
|
||||
} else {
|
||||
*if_version_maj = rsp->if_version_maj;
|
||||
*if_version_min = rsp->if_version_min;
|
||||
CDBG("TZ If version %d.%d\n", *if_version_maj,
|
||||
*if_version_min);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int32_t msm_camera_tz_load_ta(void)
|
||||
{
|
||||
int32_t rc = 0;
|
||||
|
||||
if (MSM_CAMERA_TZ_BOOT_PROTECTED &&
|
||||
msm_camera_tz_ctrl.ta_enabled > 0) {
|
||||
CDBG("TA loaded from boot(TA %s - %d)\n",
|
||||
msm_camera_tz_ctrl.ta_name,
|
||||
msm_camera_tz_ctrl.ta_enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CDBG("Enter (TA name = %s, %d)\n",
|
||||
msm_camera_tz_ctrl.ta_name,
|
||||
msm_camera_tz_ctrl.ta_enabled);
|
||||
|
||||
msm_camera_tz_lock();
|
||||
if (msm_camera_tz_ctrl.ta_enabled == 0) {
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
/* Start the TA */
|
||||
if ((msm_camera_tz_ctrl.ta_qseecom_handle == NULL) &&
|
||||
(msm_camera_tz_ctrl.ta_name != NULL) &&
|
||||
('\0' != msm_camera_tz_ctrl.ta_name[0])) {
|
||||
uint32_t if_version_maj = 0;
|
||||
uint32_t if_version_min = 0;
|
||||
|
||||
rc = qseecom_start_app(
|
||||
&msm_camera_tz_ctrl.ta_qseecom_handle,
|
||||
(char *)msm_camera_tz_ctrl.ta_name,
|
||||
QSEECOM_SBUFF_SIZE);
|
||||
if (!rc)
|
||||
rc = msm_camera_tz_i2c_ta_get_if_version(
|
||||
msm_camera_tz_ctrl.ta_qseecom_handle,
|
||||
&if_version_maj, &if_version_min);
|
||||
|
||||
if (!rc) {
|
||||
if (if_version_maj != TA_IF_VERSION_MAJ) {
|
||||
CDBG("TA ver mismatch %d.%d != %d.%d\n",
|
||||
if_version_maj, if_version_min,
|
||||
TA_IF_VERSION_MAJ,
|
||||
TA_IF_VERSION_MIN);
|
||||
rc = qseecom_shutdown_app(
|
||||
&msm_camera_tz_ctrl.
|
||||
ta_qseecom_handle);
|
||||
msm_camera_tz_ctrl.ta_qseecom_handle
|
||||
= EMPTY_QSEECOM_HANDLE;
|
||||
rc = -EFAULT;
|
||||
} else {
|
||||
msm_camera_tz_ctrl.ta_enabled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
CDBG("Load TA %s - %s(%d) - %lluus\n",
|
||||
msm_camera_tz_ctrl.ta_name,
|
||||
(msm_camera_tz_ctrl.ta_enabled)?"Ok" :
|
||||
"Failed", rc,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
} else {
|
||||
msm_camera_tz_ctrl.ta_enabled++;
|
||||
CDBG("TA already loaded (TA %s - %d)\n",
|
||||
msm_camera_tz_ctrl.ta_name,
|
||||
msm_camera_tz_ctrl.ta_enabled);
|
||||
}
|
||||
msm_camera_tz_unlock();
|
||||
return rc;
|
||||
}
|
||||
|
||||
int32_t msm_camera_tz_unload_ta(void)
|
||||
{
|
||||
int32_t rc = -EFAULT;
|
||||
|
||||
if (MSM_CAMERA_TZ_BOOT_PROTECTED) {
|
||||
CDBG("TA loaded from boot(TA %s - %d)\n",
|
||||
msm_camera_tz_ctrl.ta_name,
|
||||
msm_camera_tz_ctrl.ta_enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CDBG("Enter (TA name = %s, %d)\n",
|
||||
msm_camera_tz_ctrl.ta_name,
|
||||
msm_camera_tz_ctrl.ta_enabled);
|
||||
|
||||
msm_camera_tz_lock();
|
||||
if (msm_camera_tz_ctrl.ta_enabled == 1) {
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
rc = qseecom_shutdown_app(&msm_camera_tz_ctrl.
|
||||
ta_qseecom_handle);
|
||||
msm_camera_tz_ctrl.ta_qseecom_handle
|
||||
= EMPTY_QSEECOM_HANDLE;
|
||||
msm_camera_tz_ctrl.ta_enabled = 0;
|
||||
CDBG("Unload TA %s - %s(%d) - %lluus\n",
|
||||
msm_camera_tz_ctrl.ta_name,
|
||||
(!rc)?"Ok":"Failed", rc,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
} else {
|
||||
msm_camera_tz_ctrl.ta_enabled--;
|
||||
CDBG("TA still loaded (TA %s - %d)\n",
|
||||
msm_camera_tz_ctrl.ta_name,
|
||||
msm_camera_tz_ctrl.ta_enabled);
|
||||
}
|
||||
msm_camera_tz_unlock();
|
||||
return rc;
|
||||
}
|
||||
|
||||
int32_t msm_camera_tz_ta_set_mode(uint32_t mode,
|
||||
uint32_t hw_block)
|
||||
{
|
||||
int32_t cmd_len, rsp_len;
|
||||
struct msm_camera_tz_set_mode_req_t *cmd;
|
||||
struct msm_camera_tz_set_mode_rsp_t *rsp;
|
||||
int32_t rc = 0;
|
||||
struct qseecom_handle *ta_qseecom_handle =
|
||||
msm_camera_tz_get_ta_handle();
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
if (ta_qseecom_handle == NULL) {
|
||||
pr_err("%s:%d - Bad parameters\n",
|
||||
__func__, __LINE__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cmd_len = sizeof(struct msm_camera_tz_set_mode_req_t);
|
||||
rsp_len = sizeof(struct msm_camera_tz_set_mode_rsp_t);
|
||||
|
||||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = MSM_CAMERA_TZ_CMD_SET_MODE;
|
||||
cmd->mode = mode;
|
||||
cmd->hw_block = hw_block;
|
||||
|
||||
rc = qseecom_send_command(ta_qseecom_handle,
|
||||
(void *)cmd, cmd_len, (void *)rsp, rsp_len);
|
||||
|
||||
if (rc < 0) {
|
||||
pr_err("%s:%d - Failed: rc=%d\n",
|
||||
__func__, __LINE__,
|
||||
rc);
|
||||
return rc;
|
||||
}
|
||||
rc = rsp->rc;
|
||||
}
|
||||
CDBG("Done: rc=%d, Mode=0x%08X - %lluus\n",
|
||||
rc, mode,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
return rc;
|
||||
}
|
||||
|
||||
uint32_t msm_camera_tz_set_mode(uint32_t mode,
|
||||
uint32_t hw_block)
|
||||
{
|
||||
uint32_t rc = 0;
|
||||
|
||||
switch (mode) {
|
||||
case MSM_CAMERA_TZ_MODE_SECURE:
|
||||
rc = msm_camera_tz_load_ta();
|
||||
if (!rc) {
|
||||
rc = msm_camera_tz_ta_set_mode(mode, hw_block);
|
||||
if (rc)
|
||||
msm_camera_tz_ctrl.secure_hw_blocks |= hw_block;
|
||||
}
|
||||
break;
|
||||
case MSM_CAMERA_TZ_MODE_NON_SECURE:
|
||||
msm_camera_tz_ta_set_mode(mode, hw_block);
|
||||
if (rc)
|
||||
msm_camera_tz_ctrl.secure_hw_blocks &= ~hw_block;
|
||||
rc = msm_camera_tz_unload_ta();
|
||||
break;
|
||||
default:
|
||||
pr_err("%s:%d - Incorrect mode: %d (hw: 0x%08X)\n",
|
||||
__func__, __LINE__,
|
||||
mode, hw_block);
|
||||
return -EINVAL;
|
||||
}
|
||||
CDBG("Set Mode - rc=%d, Mode: 0x%08X\n",
|
||||
rc, mode);
|
||||
return rc;
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
* only version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __MSM_CAMERA_TZ_UTIL_H
|
||||
#define __MSM_CAMERA_TZ_UTIL_H
|
||||
|
||||
#include <soc/qcom/camera2.h>
|
||||
|
||||
#ifndef CONFIG_MSM_CAMERA_TZ_TA_NAME
|
||||
#define CONFIG_MSM_CAMERA_TZ_TA_NAME "seccamdemo64"
|
||||
#endif /* CONFIG_MSM_CAMERA_TZ_TA_NAME */
|
||||
|
||||
#define MSM_CAMERA_TZ_MODE_NON_SECURE 0x0000000000
|
||||
#define MSM_CAMERA_TZ_MODE_SECURE 0x0000000001
|
||||
|
||||
#define MSM_CAMERA_TZ_HW_BLOCK_CSIDCORE 0x0000000001
|
||||
#define MSM_CAMERA_TZ_HW_BLOCK_ISPIF 0x0000000002
|
||||
#define MSM_CAMERA_TZ_HW_BLOCK_CCI 0x0000000004
|
||||
#define MSM_CAMERA_TZ_HW_BLOCK_ISP 0x0000000008
|
||||
#define MSM_CAMERA_TZ_HW_BLOCK_CPP 0x0000000010
|
||||
|
||||
enum msm_camera_tz_cmd_id_t {
|
||||
MSM_CAMERA_TZ_CMD_NONE,
|
||||
MSM_CAMERA_TZ_CMD_GET_IF_VERSION,
|
||||
MSM_CAMERA_TZ_CMD_POWER_UP,
|
||||
MSM_CAMERA_TZ_CMD_POWER_DOWN,
|
||||
MSM_CAMERA_TZ_CMD_CCI_GENERIC,
|
||||
MSM_CAMERA_TZ_CMD_CCI_READ,
|
||||
MSM_CAMERA_TZ_CMD_CCI_READ_SEQ,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE_SEQ,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE_ASYNC,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE_SYNC,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE_SYNC_BLOCK,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE_SEQ_TABLE,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE_W_MICRODELAY,
|
||||
MSM_CAMERA_TZ_CMD_CCI_POLL,
|
||||
MSM_CAMERA_TZ_CMD_CCI_WRITE_CONF_TBL,
|
||||
MSM_CAMERA_TZ_CMD_CCI_UTIL,
|
||||
MSM_CAMERA_TZ_CMD_SET_MODE,
|
||||
MSM_CAMERA_TZ_CMD_FRAME_NOTIFICATION,
|
||||
};
|
||||
|
||||
enum msm_camera_tz_status_t {
|
||||
MSM_CAMERA_TZ_STATUS_SUCCESS = 0,
|
||||
MSM_CAMERA_TZ_STATUS_GENERAL_FAILURE = -1,
|
||||
MSM_CAMERA_TZ_STATUS_INVALID_INPUT_PARAMS = -2,
|
||||
MSM_CAMERA_TZ_STATUS_INVALID_SENSOR_ID = -3,
|
||||
MSM_CAMERA_TZ_STATUS_BYPASS = -4,
|
||||
MSM_CAMERA_TZ_STATUS_TIMEOUT = -5,
|
||||
|
||||
MSM_CAMERA_TZ_STATUS_RESET_DONE = 1,
|
||||
MSM_CAMERA_TZ_STATUS_ERR_SIZE = 0x7FFFFFFF
|
||||
};
|
||||
|
||||
#pragma pack(push, msm_camera_tz, 1)
|
||||
|
||||
struct msm_camera_tz_generic_req_t {
|
||||
enum msm_camera_tz_cmd_id_t cmd_id;
|
||||
};
|
||||
|
||||
struct msm_camera_tz_generic_rsp_t {
|
||||
enum msm_camera_tz_status_t rc;
|
||||
};
|
||||
|
||||
#pragma pack(pop, msm_camera_tz)
|
||||
|
||||
uint32_t msm_camera_tz_set_mode(
|
||||
uint32_t mode, uint32_t hw_block);
|
||||
|
||||
struct qseecom_handle *msm_camera_tz_get_ta_handle(void);
|
||||
int32_t get_cmd_rsp_buffers(
|
||||
struct qseecom_handle *ta_qseecom_handle,
|
||||
void **cmd, int *cmd_len,
|
||||
void **rsp, int *rsp_len);
|
||||
int32_t msm_camera_tz_load_ta(void);
|
||||
int32_t msm_camera_tz_unload_ta(void);
|
||||
void msm_camera_tz_lock(void);
|
||||
void msm_camera_tz_unlock(void);
|
||||
|
||||
#endif /* __MSM_CAMERA_TZ_UTIL_H */
|
|
@ -15,113 +15,62 @@
|
|||
#include <soc/qcom/camera2.h>
|
||||
#include "qseecom_kernel.h"
|
||||
#include "msm_camera_i2c.h"
|
||||
#include "msm_camera_io_util.h"
|
||||
#include "msm_camera_tz_util.h"
|
||||
#include "msm_cci.h"
|
||||
#include "msm_sensor.h"
|
||||
|
||||
#define QSEECOM_SBUFF_SIZE SZ_128K
|
||||
#define MAX_TA_NAME 32
|
||||
#define EMPTY_QSEECOM_HANDLE NULL
|
||||
|
||||
#ifndef CONFIG_MSM_SEC_CCI_TA_NAME
|
||||
#define CONFIG_MSM_SEC_CCI_TA_NAME "seccamdemo64"
|
||||
#endif /* CONFIG_MSM_SEC_CCI_TA_NAME */
|
||||
|
||||
/* Update version major number in case the HLOS-TA interface is changed*/
|
||||
#define TA_IF_VERSION_MAJ 0
|
||||
#define TA_IF_VERSION_MIN 1
|
||||
|
||||
#undef CDBG
|
||||
#define MSM_CAMERA_TZ_I2C_VERBOSE
|
||||
|
||||
#ifdef CONFIG_MSM_SEC_CCI_DEBUG
|
||||
|
||||
#define CDBG(fmt, args...) pr_info(CONFIG_MSM_SEC_CCI_TA_NAME "::%s:%d - " fmt,\
|
||||
__func__, __LINE__, ##args)
|
||||
#define TZ_I2C_FN_RETURN(ret, i2c_fn, ...) \
|
||||
((ret < 0) ? i2c_fn(__VA_ARGS__):ret)
|
||||
|
||||
#define TZ_I2C_FN_RETURN(ret, i2c_fn, ...) \
|
||||
((ret < 0) ? i2c_fn(__VA_ARGS__):ret)
|
||||
#else /* CONFIG_MSM_SEC_CCI_DEBUG */
|
||||
|
||||
#define CDBG(fmt, args...) pr_info("%s:%d - " fmt, __func__, __LINE__, ##args)
|
||||
#define TZ_I2C_FN_RETURN(ret, i2c_fn, ...) \
|
||||
((ret < 0) ? -EFAULT:ret)
|
||||
|
||||
#define TZ_I2C_FN_RETURN(ret, i2c_fn, ...) \
|
||||
((ret < 0) ? -EFAULT:ret)
|
||||
#endif /* CONFIG_MSM_SEC_CCI_DEBUG */
|
||||
|
||||
#ifdef MSM_CAMERA_TZ_I2C_VERBOSE
|
||||
#define CDBG(fmt, args...) \
|
||||
pr_info(CONFIG_MSM_SEC_CCI_TA_NAME "::%s:%d - " fmt, \
|
||||
__func__, __LINE__, ##args)
|
||||
#else /* MSM_CAMERA_TZ_I2C_VERBOSE */
|
||||
#define CDBG(fmt, args...) \
|
||||
pr_debug("%s:%d - " fmt, __func__, __LINE__, ##args)
|
||||
#endif /* MSM_CAMERA_TZ_I2C_VERBOSE */
|
||||
|
||||
#pragma pack(push, msm_camera_tz_i2c, 1)
|
||||
|
||||
enum msm_camera_tz_i2c_cmd_id_t {
|
||||
TZ_I2C_CMD_GET_NONE,
|
||||
TZ_I2C_CMD_GET_IF_VERSION,
|
||||
TZ_I2C_CMD_POWER_UP,
|
||||
TZ_I2C_CMD_POWER_DOWN,
|
||||
TZ_I2C_CMD_CCI_GENERIC,
|
||||
TZ_I2C_CMD_CCI_READ,
|
||||
TZ_I2C_CMD_CCI_READ_SEQ,
|
||||
TZ_I2C_CMD_CCI_WRITE,
|
||||
TZ_I2C_CMD_CCI_WRITE_SEQ,
|
||||
TZ_I2C_CMD_CCI_WRITE_TABLE_ASYNC,
|
||||
TZ_I2C_CMD_CCI_WRITE_TABLE_SYNC,
|
||||
TZ_I2C_CMD_CCI_WRITE_TABLE_SYNC_BLOCK,
|
||||
TZ_I2C_CMD_CCI_WRITE_TABLE,
|
||||
TZ_I2C_CMD_CCI_WRITE_SEQ_TABLE,
|
||||
TZ_I2C_CMD_CCI_WRITE_TABLE_W_MICRODELAY,
|
||||
TZ_I2C_CMD_CCI_POLL,
|
||||
TZ_I2C_CMD_CCI_WRITE_CONF_TBL,
|
||||
TZ_I2C_CMD_CCI_UTIL,
|
||||
};
|
||||
|
||||
enum msm_camera_tz_i2c_status_t {
|
||||
TZ_I2C_STATUS_SUCCESS = 0,
|
||||
TZ_I2C_STATUS_GENERAL_FAILURE = -1,
|
||||
TZ_I2C_STATUS_INVALID_INPUT_PARAMS = -2,
|
||||
TZ_I2C_STATUS_INVALID_SENSOR_ID = -3,
|
||||
TZ_I2C_STATUS_BYPASS = -4,
|
||||
TZ_I2C_STATUS_ERR_SIZE = 0x7FFFFFFF
|
||||
};
|
||||
|
||||
struct msm_camera_tz_i2c_generic_req_t {
|
||||
enum msm_camera_tz_i2c_cmd_id_t cmd_id;
|
||||
};
|
||||
|
||||
struct msm_camera_tz_i2c_generic_rsp_t {
|
||||
enum msm_camera_tz_i2c_status_t rc;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_i2c_get_if_version_req_t msm_camera_tz_i2c_generic_req_t
|
||||
|
||||
struct msm_camera_tz_i2c_get_if_version_rsp_t {
|
||||
enum msm_camera_tz_i2c_status_t rc;
|
||||
uint32_t if_version_maj;
|
||||
uint32_t if_version_min;
|
||||
};
|
||||
|
||||
struct msm_camera_tz_i2c_power_up_req_t {
|
||||
enum msm_camera_tz_i2c_cmd_id_t cmd_id;
|
||||
int32_t sensor_id;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_i2c_power_up_rsp_t msm_camera_tz_i2c_generic_rsp_t
|
||||
|
||||
struct msm_camera_tz_i2c_power_down_req_t {
|
||||
enum msm_camera_tz_i2c_cmd_id_t cmd_id;
|
||||
int32_t sensor_id;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_i2c_power_down_rsp_t msm_camera_tz_i2c_generic_rsp_t
|
||||
|
||||
struct msm_camera_tz_i2c_cci_generic_req_t {
|
||||
enum msm_camera_tz_i2c_cmd_id_t cmd_id;
|
||||
enum msm_camera_tz_cmd_id_t cmd_id;
|
||||
int32_t sensor_id;
|
||||
enum msm_camera_tz_i2c_cmd_id_t cci_cmd_id;
|
||||
enum msm_camera_tz_cmd_id_t cci_cmd_id;
|
||||
uint32_t cci_i2c_master;
|
||||
uint16_t sid;
|
||||
uint16_t cid;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_i2c_cci_generic_rsp_t msm_camera_tz_i2c_generic_rsp_t
|
||||
#define msm_camera_tz_i2c_cci_generic_rsp_t msm_camera_tz_generic_rsp_t
|
||||
|
||||
/* MSM_CAMERA_TZ_CMD_POWER_UP */
|
||||
struct msm_camera_tz_i2c_power_up_req_t {
|
||||
enum msm_camera_tz_cmd_id_t cmd_id;
|
||||
int32_t sensor_id;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_i2c_power_up_rsp_t msm_camera_tz_generic_rsp_t
|
||||
|
||||
/* MSM_CAMERA_TZ_CMD_POWER_DOWN */
|
||||
struct msm_camera_tz_i2c_power_down_req_t {
|
||||
enum msm_camera_tz_cmd_id_t cmd_id;
|
||||
int32_t sensor_id;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_i2c_power_down_rsp_t msm_camera_tz_generic_rsp_t
|
||||
|
||||
/* MSM_CAMERA_TZ_CMD_CCI_READ */
|
||||
struct msm_camera_tz_i2c_cci_read_req_t {
|
||||
enum msm_camera_tz_i2c_cmd_id_t cmd_id;
|
||||
enum msm_camera_tz_cmd_id_t cmd_id;
|
||||
int32_t sensor_id;
|
||||
uint32_t cci_i2c_master;
|
||||
uint16_t sid;
|
||||
|
@ -131,12 +80,13 @@ struct msm_camera_tz_i2c_cci_read_req_t {
|
|||
};
|
||||
|
||||
struct msm_camera_tz_i2c_cci_read_rsp_t {
|
||||
enum msm_camera_tz_i2c_status_t rc;
|
||||
enum msm_camera_tz_status_t rc;
|
||||
uint16_t data;
|
||||
};
|
||||
|
||||
/* MSM_CAMERA_TZ_CMD_CCI_WRITE */
|
||||
struct msm_camera_tz_i2c_cci_write_req_t {
|
||||
enum msm_camera_tz_i2c_cmd_id_t cmd_id;
|
||||
enum msm_camera_tz_cmd_id_t cmd_id;
|
||||
int32_t sensor_id;
|
||||
uint32_t cci_i2c_master;
|
||||
uint16_t sid;
|
||||
|
@ -146,10 +96,11 @@ struct msm_camera_tz_i2c_cci_write_req_t {
|
|||
uint32_t data_type;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_i2c_cci_write_rsp_t msm_camera_tz_i2c_generic_rsp_t
|
||||
#define msm_camera_tz_i2c_cci_write_rsp_t msm_camera_tz_generic_rsp_t
|
||||
|
||||
/* MSM_CAMERA_TZ_CMD_CCI_UTIL */
|
||||
struct msm_camera_tz_i2c_cci_util_req_t {
|
||||
enum msm_camera_tz_i2c_cmd_id_t cmd_id;
|
||||
enum msm_camera_tz_cmd_id_t cmd_id;
|
||||
int32_t sensor_id;
|
||||
uint32_t cci_i2c_master;
|
||||
uint16_t sid;
|
||||
|
@ -157,33 +108,19 @@ struct msm_camera_tz_i2c_cci_util_req_t {
|
|||
uint16_t cci_cmd;
|
||||
};
|
||||
|
||||
#define msm_camera_tz_i2c_cci_util_rsp_t msm_camera_tz_i2c_generic_rsp_t
|
||||
#define msm_camera_tz_i2c_cci_util_rsp_t msm_camera_tz_generic_rsp_t
|
||||
|
||||
#pragma pack(pop, msm_camera_tz_i2c)
|
||||
|
||||
/* Camera control structure */
|
||||
struct msm_camera_tz_i2c_sensor_info_t {
|
||||
struct msm_sensor_ctrl_t *s_ctrl;
|
||||
struct msm_camera_i2c_fn_t *saved_sensor_i2c_fn;
|
||||
uint32_t secure;
|
||||
uint32_t ta_enabled;
|
||||
struct qseecom_handle *ta_qseecom_handle;
|
||||
const char *ta_name;
|
||||
uint32_t ready;
|
||||
};
|
||||
|
||||
struct msm_camera_tz_i2c_ctrl_t {
|
||||
struct mutex lock;
|
||||
uint32_t lock_ready;
|
||||
uint32_t secure_mode;
|
||||
};
|
||||
|
||||
static struct msm_camera_tz_i2c_ctrl_t msm_camera_tz_i2c_ctrl;
|
||||
|
||||
static struct msm_camera_tz_i2c_sensor_info_t sensor_info[MAX_CAMERAS] = {
|
||||
{NULL, NULL, 0, 0, NULL, CONFIG_MSM_SEC_CCI_TA_NAME},
|
||||
{NULL, NULL, 0, 0, NULL, CONFIG_MSM_SEC_CCI_TA_NAME},
|
||||
{NULL, NULL, 0, 0, NULL, CONFIG_MSM_SEC_CCI_TA_NAME},
|
||||
{NULL, NULL, 0, 0, NULL, CONFIG_MSM_SEC_CCI_TA_NAME},
|
||||
};
|
||||
static struct msm_camera_tz_i2c_sensor_info_t sensor_info[MAX_CAMERAS];
|
||||
|
||||
static int32_t msm_camera_tz_i2c_is_sensor_secure(
|
||||
struct msm_camera_i2c_client *client)
|
||||
|
@ -196,7 +133,6 @@ static int32_t msm_camera_tz_i2c_is_sensor_secure(
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
CDBG("Enter\n");
|
||||
for (index = 0; index < MAX_CAMERAS; index++) {
|
||||
if ((sensor_info[index].s_ctrl != NULL) &&
|
||||
sensor_info[index].secure &&
|
||||
|
@ -210,88 +146,6 @@ static int32_t msm_camera_tz_i2c_is_sensor_secure(
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int32_t get_cmd_rsp_buffers(
|
||||
struct qseecom_handle *ta_qseecom_handle,
|
||||
void **cmd, int *cmd_len,
|
||||
void **rsp, int *rsp_len)
|
||||
{
|
||||
|
||||
CDBG("Enter\n");
|
||||
if ((ta_qseecom_handle == NULL) ||
|
||||
(cmd == NULL) || (cmd_len == NULL) ||
|
||||
(rsp == NULL) || (rsp_len == NULL)) {
|
||||
pr_err("%s:%d - Bad parameters\n",
|
||||
__func__, __LINE__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (*cmd_len & QSEECOM_ALIGN_MASK)
|
||||
*cmd_len = QSEECOM_ALIGN(*cmd_len);
|
||||
|
||||
if (*rsp_len & QSEECOM_ALIGN_MASK)
|
||||
*rsp_len = QSEECOM_ALIGN(*rsp_len);
|
||||
|
||||
if ((*rsp_len + *cmd_len) > QSEECOM_SBUFF_SIZE) {
|
||||
pr_err("%s:%d - Shared buffer too small to hold cmd=%d and rsp=%d\n",
|
||||
__func__, __LINE__,
|
||||
*cmd_len, *rsp_len);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*cmd = ta_qseecom_handle->sbuf;
|
||||
*rsp = ta_qseecom_handle->sbuf + *cmd_len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t msm_camera_tz_i2c_ta_get_if_version(
|
||||
struct qseecom_handle *ta_qseecom_handle,
|
||||
uint32_t *if_version_maj,
|
||||
uint32_t *if_version_min)
|
||||
{
|
||||
int32_t cmd_len, rsp_len;
|
||||
struct msm_camera_tz_i2c_get_if_version_req_t *cmd;
|
||||
struct msm_camera_tz_i2c_get_if_version_rsp_t *rsp;
|
||||
int32_t rc = 0;
|
||||
|
||||
CDBG("Enter\n");
|
||||
if ((ta_qseecom_handle == NULL) ||
|
||||
(if_version_maj == NULL) || (if_version_min == NULL)) {
|
||||
pr_err("%s:%d - Bad parameters\n",
|
||||
__func__, __LINE__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cmd_len = sizeof(struct msm_camera_tz_i2c_get_if_version_req_t);
|
||||
rsp_len = sizeof(struct msm_camera_tz_i2c_get_if_version_rsp_t);
|
||||
|
||||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = TZ_I2C_CMD_GET_IF_VERSION;
|
||||
|
||||
rc = qseecom_send_command(ta_qseecom_handle,
|
||||
(void *)cmd, cmd_len, (void *)rsp, rsp_len);
|
||||
|
||||
if (rc < 0) {
|
||||
pr_err("%s:%d - Unable to get if version info, rc=%d\n",
|
||||
__func__, __LINE__,
|
||||
rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rsp->rc < 0) {
|
||||
CDBG("TZ I2C App error, rc=%d\n", rsp->rc);
|
||||
rc = -EFAULT;
|
||||
} else {
|
||||
*if_version_maj = rsp->if_version_maj;
|
||||
*if_version_min = rsp->if_version_min;
|
||||
CDBG("TZ I2C If version %d.%d\n", *if_version_maj,
|
||||
*if_version_min);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int32_t msm_camera_tz_i2c_ta_power_up(
|
||||
struct qseecom_handle *ta_qseecom_handle,
|
||||
int32_t sensor_id,
|
||||
|
@ -304,12 +158,14 @@ static int32_t msm_camera_tz_i2c_ta_power_up(
|
|||
|
||||
CDBG("Enter\n");
|
||||
|
||||
if (sensor_secure == NULL)
|
||||
if (sensor_secure == NULL) {
|
||||
pr_err("%s:%d - Bad parameter\n",
|
||||
__func__, __LINE__);
|
||||
return -EINVAL;
|
||||
|
||||
}
|
||||
*sensor_secure = 0;
|
||||
|
||||
if ((ta_qseecom_handle == NULL) ||
|
||||
(sensor_secure == NULL) ||
|
||||
(sensor_id < 0) ||
|
||||
(sensor_id >= MAX_CAMERAS)) {
|
||||
pr_err("%s:%d - Bad parameters\n",
|
||||
|
@ -323,7 +179,7 @@ static int32_t msm_camera_tz_i2c_ta_power_up(
|
|||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = TZ_I2C_CMD_POWER_UP;
|
||||
cmd->cmd_id = MSM_CAMERA_TZ_CMD_POWER_UP;
|
||||
cmd->sensor_id = sensor_id;
|
||||
|
||||
rc = qseecom_send_command(ta_qseecom_handle,
|
||||
|
@ -336,7 +192,7 @@ static int32_t msm_camera_tz_i2c_ta_power_up(
|
|||
return rc;
|
||||
}
|
||||
|
||||
if (rsp->rc == TZ_I2C_STATUS_SUCCESS)
|
||||
if (rsp->rc == MSM_CAMERA_TZ_STATUS_SUCCESS)
|
||||
*sensor_secure = 1;
|
||||
CDBG("Sensor %d is %s\n", sensor_id,
|
||||
(*sensor_secure)?"SECURE":"NON-SECURE");
|
||||
|
@ -369,7 +225,7 @@ static int32_t msm_camera_tz_i2c_ta_power_down(
|
|||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = TZ_I2C_CMD_POWER_DOWN;
|
||||
cmd->cmd_id = MSM_CAMERA_TZ_CMD_POWER_DOWN;
|
||||
cmd->sensor_id = sensor_id;
|
||||
|
||||
rc = qseecom_send_command(ta_qseecom_handle,
|
||||
|
@ -387,7 +243,7 @@ static int32_t msm_camera_tz_i2c_ta_power_down(
|
|||
|
||||
static int32_t msm_camera_tz_i2c_ta_cci_generic(
|
||||
struct msm_camera_i2c_client *client,
|
||||
enum msm_camera_tz_i2c_cmd_id_t cci_cmd_id)
|
||||
enum msm_camera_tz_cmd_id_t cci_cmd_id)
|
||||
{
|
||||
int32_t cmd_len, rsp_len;
|
||||
struct msm_camera_tz_i2c_cci_generic_req_t *cmd;
|
||||
|
@ -395,6 +251,7 @@ static int32_t msm_camera_tz_i2c_ta_cci_generic(
|
|||
int32_t rc = 0;
|
||||
struct qseecom_handle *ta_qseecom_handle;
|
||||
int32_t sensor_id = msm_camera_tz_i2c_is_sensor_secure(client);
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
if ((client == NULL) ||
|
||||
(sensor_id < 0) ||
|
||||
|
@ -404,21 +261,14 @@ static int32_t msm_camera_tz_i2c_ta_cci_generic(
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
CDBG("Sensor=%d, MS=%d, SID=%d, CID=%d, cci_cmd_id=%d\n",
|
||||
sensor_id,
|
||||
client->cci_client->cci_i2c_master,
|
||||
client->cci_client->sid,
|
||||
client->cci_client->cid,
|
||||
cci_cmd_id);
|
||||
|
||||
ta_qseecom_handle = sensor_info[sensor_id].ta_qseecom_handle;
|
||||
ta_qseecom_handle = msm_camera_tz_get_ta_handle();
|
||||
cmd_len = sizeof(struct msm_camera_tz_i2c_cci_generic_req_t);
|
||||
rsp_len = sizeof(struct msm_camera_tz_i2c_cci_generic_rsp_t);
|
||||
|
||||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = TZ_I2C_CMD_CCI_GENERIC;
|
||||
cmd->cmd_id = MSM_CAMERA_TZ_CMD_CCI_GENERIC;
|
||||
cmd->sensor_id = sensor_id;
|
||||
cmd->cci_cmd_id = cci_cmd_id;
|
||||
cmd->cci_i2c_master = client->cci_client->cci_i2c_master;
|
||||
|
@ -435,8 +285,15 @@ static int32_t msm_camera_tz_i2c_ta_cci_generic(
|
|||
return rc;
|
||||
}
|
||||
rc = rsp->rc;
|
||||
CDBG("Done: rc=%d, cci_cmd_id=%d\n", rc, cci_cmd_id);
|
||||
}
|
||||
CDBG("Done: rc=%d, SN=%d, MS=%d, SID=%d, CID=%d, CMD=%d - %lluus\n",
|
||||
rc, sensor_id,
|
||||
client->cci_client->cci_i2c_master,
|
||||
client->cci_client->sid,
|
||||
client->cci_client->cid,
|
||||
cci_cmd_id,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -452,6 +309,7 @@ static int32_t msm_camera_tz_i2c_ta_cci_read(
|
|||
int32_t rc = 0;
|
||||
struct qseecom_handle *ta_qseecom_handle;
|
||||
int32_t sensor_id = msm_camera_tz_i2c_is_sensor_secure(client);
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
if ((client == NULL) ||
|
||||
(data == NULL) ||
|
||||
|
@ -462,22 +320,14 @@ static int32_t msm_camera_tz_i2c_ta_cci_read(
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
CDBG("Sensor=%d, MS=%d, SID=%d, CID=%d, Addr=0x%X, Type=%d\n",
|
||||
sensor_id,
|
||||
client->cci_client->cci_i2c_master,
|
||||
client->cci_client->sid,
|
||||
client->cci_client->cid,
|
||||
addr,
|
||||
data_type);
|
||||
|
||||
ta_qseecom_handle = sensor_info[sensor_id].ta_qseecom_handle;
|
||||
ta_qseecom_handle = msm_camera_tz_get_ta_handle();
|
||||
cmd_len = sizeof(struct msm_camera_tz_i2c_cci_read_req_t);
|
||||
rsp_len = sizeof(struct msm_camera_tz_i2c_cci_read_rsp_t);
|
||||
|
||||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = TZ_I2C_CMD_CCI_READ;
|
||||
cmd->cmd_id = MSM_CAMERA_TZ_CMD_CCI_READ;
|
||||
cmd->sensor_id = sensor_id;
|
||||
cmd->cci_i2c_master = client->cci_client->cci_i2c_master;
|
||||
cmd->sid = client->cci_client->sid;
|
||||
|
@ -496,10 +346,17 @@ static int32_t msm_camera_tz_i2c_ta_cci_read(
|
|||
}
|
||||
rc = rsp->rc;
|
||||
*data = rsp->data;
|
||||
|
||||
CDBG("Done: rc=%d, addr=0x%X, data=0x%X\n", rc,
|
||||
addr, *data);
|
||||
}
|
||||
CDBG("Done: rc=%d, SN=%d, MS=%d, SID=%d, CID=%d, ", rc,
|
||||
sensor_id,
|
||||
client->cci_client->cci_i2c_master,
|
||||
client->cci_client->sid,
|
||||
client->cci_client->cid);
|
||||
|
||||
CDBG("Addr=0x%X, Type=%d, Data=0x%X - %lluus\n",
|
||||
addr, data_type, *data,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -515,6 +372,7 @@ static int32_t msm_camera_tz_i2c_ta_cci_write(
|
|||
int32_t rc = 0;
|
||||
struct qseecom_handle *ta_qseecom_handle;
|
||||
int32_t sensor_id = msm_camera_tz_i2c_is_sensor_secure(client);
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
if ((client == NULL) ||
|
||||
(sensor_id < 0) ||
|
||||
|
@ -524,23 +382,14 @@ static int32_t msm_camera_tz_i2c_ta_cci_write(
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
CDBG("Sensor=%d, MS=%d, SID=%d, CID=%d, Addr=0x%X, Data=0x%X Type=%d\n",
|
||||
sensor_id,
|
||||
client->cci_client->cci_i2c_master,
|
||||
client->cci_client->sid,
|
||||
client->cci_client->cid,
|
||||
addr,
|
||||
data,
|
||||
data_type);
|
||||
|
||||
ta_qseecom_handle = sensor_info[sensor_id].ta_qseecom_handle;
|
||||
ta_qseecom_handle = msm_camera_tz_get_ta_handle();
|
||||
cmd_len = sizeof(struct msm_camera_tz_i2c_cci_write_req_t);
|
||||
rsp_len = sizeof(struct msm_camera_tz_i2c_cci_write_rsp_t);
|
||||
|
||||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = TZ_I2C_CMD_CCI_WRITE;
|
||||
cmd->cmd_id = MSM_CAMERA_TZ_CMD_CCI_WRITE;
|
||||
cmd->sensor_id = sensor_id;
|
||||
cmd->cci_i2c_master = client->cci_client->cci_i2c_master;
|
||||
cmd->sid = client->cci_client->sid;
|
||||
|
@ -559,10 +408,17 @@ static int32_t msm_camera_tz_i2c_ta_cci_write(
|
|||
return rc;
|
||||
}
|
||||
rc = rsp->rc;
|
||||
|
||||
CDBG("Done: rc=%d, addr=0x%X, data=0x%X\n", rc,
|
||||
addr, data);
|
||||
}
|
||||
CDBG("Done: rc=%d, SN=%d, MS=%d, SID=%d, CID=%d, ", rc,
|
||||
sensor_id,
|
||||
client->cci_client->cci_i2c_master,
|
||||
client->cci_client->sid,
|
||||
client->cci_client->cid);
|
||||
|
||||
CDBG("Addr=0x%X, Data=0x%X Type=%d - %lluus\n",
|
||||
addr, data, data_type,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -576,6 +432,7 @@ static int32_t msm_camera_tz_i2c_ta_cci_util(
|
|||
int32_t rc = 0;
|
||||
struct qseecom_handle *ta_qseecom_handle;
|
||||
int32_t sensor_id = msm_camera_tz_i2c_is_sensor_secure(client);
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
if ((client == NULL) ||
|
||||
(sensor_id < 0) ||
|
||||
|
@ -585,21 +442,14 @@ static int32_t msm_camera_tz_i2c_ta_cci_util(
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
CDBG("Sensor=%d, MS=%d, SID=%d, CID=%d, cci_cmd=%d\n",
|
||||
sensor_id,
|
||||
client->cci_client->cci_i2c_master,
|
||||
client->cci_client->sid,
|
||||
client->cci_client->cid,
|
||||
cci_cmd);
|
||||
|
||||
ta_qseecom_handle = sensor_info[sensor_id].ta_qseecom_handle;
|
||||
ta_qseecom_handle = msm_camera_tz_get_ta_handle();
|
||||
cmd_len = sizeof(struct msm_camera_tz_i2c_cci_util_req_t);
|
||||
rsp_len = sizeof(struct msm_camera_tz_i2c_cci_util_rsp_t);
|
||||
|
||||
rc = get_cmd_rsp_buffers(ta_qseecom_handle,
|
||||
(void **)&cmd, &cmd_len, (void **)&rsp, &rsp_len);
|
||||
if (!rc) {
|
||||
cmd->cmd_id = TZ_I2C_CMD_CCI_UTIL;
|
||||
cmd->cmd_id = MSM_CAMERA_TZ_CMD_CCI_UTIL;
|
||||
cmd->sensor_id = sensor_id;
|
||||
cmd->cci_i2c_master = client->cci_client->cci_i2c_master;
|
||||
cmd->sid = client->cci_client->sid;
|
||||
|
@ -616,8 +466,15 @@ static int32_t msm_camera_tz_i2c_ta_cci_util(
|
|||
return rc;
|
||||
}
|
||||
rc = rsp->rc;
|
||||
CDBG("Done: rc=%d, cci_cmd=%d\n", rc, cci_cmd);
|
||||
}
|
||||
CDBG("Done: rc=%d, SN=%d, MS=%d, SID=%d, CID=%d, CMD=%d - %lluus\n",
|
||||
rc, sensor_id,
|
||||
client->cci_client->cci_i2c_master,
|
||||
client->cci_client->sid,
|
||||
client->cci_client->cid,
|
||||
cci_cmd,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -628,9 +485,10 @@ static int32_t msm_camera_tz_i2c_ta_probe(
|
|||
|
||||
CDBG("Enter\n");
|
||||
sensor_id = msm_camera_tz_i2c_is_sensor_secure(client);
|
||||
if ((sensor_id >= 0) && sensor_info[sensor_id].ta_enabled
|
||||
&& msm_camera_tz_i2c_ctrl.lock_ready) {
|
||||
mutex_lock(&msm_camera_tz_i2c_ctrl.lock);
|
||||
if ((sensor_id >= 0) &&
|
||||
(sensor_id < MAX_CAMERAS) &&
|
||||
(sensor_info[sensor_id].ready != 0)) {
|
||||
msm_camera_tz_lock();
|
||||
return sensor_id;
|
||||
}
|
||||
return -EINVAL;
|
||||
|
@ -638,143 +496,74 @@ static int32_t msm_camera_tz_i2c_ta_probe(
|
|||
|
||||
static int32_t msm_camera_tz_i2c_ta_done(void)
|
||||
{
|
||||
int32_t rc = 0;
|
||||
|
||||
CDBG("Enter\n");
|
||||
if (msm_camera_tz_i2c_ctrl.lock_ready)
|
||||
mutex_unlock(&msm_camera_tz_i2c_ctrl.lock);
|
||||
return rc;
|
||||
msm_camera_tz_unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t msm_camera_tz_i2c_power_up(
|
||||
struct msm_camera_i2c_client *client)
|
||||
{
|
||||
int32_t rc = -EFAULT;
|
||||
int32_t rc = 0;
|
||||
int32_t sensor_id = msm_camera_tz_i2c_is_sensor_secure(client);
|
||||
|
||||
if (!msm_camera_tz_i2c_ctrl.lock_ready) {
|
||||
msm_camera_tz_i2c_ctrl.lock_ready = 1;
|
||||
mutex_init(&msm_camera_tz_i2c_ctrl.lock);
|
||||
}
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
CDBG("Enter (sensor_id=%d)\n", sensor_id);
|
||||
if (sensor_id >= 0) {
|
||||
ktime_t startTime;
|
||||
if ((sensor_id >= 0) && (sensor_id < MAX_CAMERAS)) {
|
||||
rc = msm_camera_tz_load_ta();
|
||||
if (!rc) {
|
||||
uint32_t sensor_secure = 0;
|
||||
|
||||
mutex_lock(&msm_camera_tz_i2c_ctrl.lock);
|
||||
if (msm_camera_tz_i2c_ctrl.secure_mode) {
|
||||
mutex_unlock(&msm_camera_tz_i2c_ctrl.lock);
|
||||
return rc;
|
||||
}
|
||||
startTime = ktime_get();
|
||||
|
||||
CDBG("Switch to secure mode (secure sensor=%d)\n",
|
||||
sensor_id);
|
||||
/* Start the TA */
|
||||
if ((sensor_info[sensor_id].ta_qseecom_handle == NULL)
|
||||
&& (sensor_info[sensor_id].ta_name != NULL) &&
|
||||
('\0' != sensor_info[sensor_id].ta_name[0])) {
|
||||
uint32_t if_version_maj = 0;
|
||||
uint32_t if_version_min = 0;
|
||||
|
||||
sensor_info[sensor_id].ta_enabled = 0;
|
||||
rc = qseecom_start_app(
|
||||
&sensor_info[sensor_id].ta_qseecom_handle,
|
||||
(char *)sensor_info[sensor_id].ta_name,
|
||||
QSEECOM_SBUFF_SIZE);
|
||||
if (!rc) {
|
||||
rc = msm_camera_tz_i2c_ta_get_if_version(
|
||||
sensor_info[sensor_id].
|
||||
ta_qseecom_handle,
|
||||
&if_version_maj, &if_version_min);
|
||||
}
|
||||
|
||||
if (!rc) {
|
||||
if (if_version_maj != TA_IF_VERSION_MAJ) {
|
||||
CDBG("TA ver mismatch %d.%d != %d.%d\n",
|
||||
if_version_maj, if_version_min,
|
||||
TA_IF_VERSION_MAJ,
|
||||
TA_IF_VERSION_MIN);
|
||||
rc = qseecom_shutdown_app(
|
||||
&sensor_info[sensor_id].
|
||||
ta_qseecom_handle);
|
||||
sensor_info[sensor_id].ta_qseecom_handle
|
||||
= EMPTY_QSEECOM_HANDLE;
|
||||
rc = -EFAULT;
|
||||
} else {
|
||||
uint32_t sensor_secure = 0;
|
||||
/*Notify TA & get sensor secure status*/
|
||||
rc = msm_camera_tz_i2c_ta_power_up(
|
||||
sensor_info[sensor_id].
|
||||
ta_qseecom_handle,
|
||||
sensor_id,
|
||||
&sensor_secure);
|
||||
if (!rc && sensor_secure)
|
||||
/* Sensor validated by TA*/
|
||||
sensor_info[sensor_id].
|
||||
ta_enabled = 1;
|
||||
else {
|
||||
qseecom_shutdown_app(
|
||||
&sensor_info[sensor_id].
|
||||
ta_qseecom_handle);
|
||||
sensor_info[sensor_id].
|
||||
ta_qseecom_handle
|
||||
= EMPTY_QSEECOM_HANDLE;
|
||||
rc = -EFAULT;
|
||||
}
|
||||
}
|
||||
msm_camera_tz_lock();
|
||||
/* Notify TA & get sensor secure status */
|
||||
rc = msm_camera_tz_i2c_ta_power_up(
|
||||
msm_camera_tz_get_ta_handle(),
|
||||
sensor_id,
|
||||
&sensor_secure);
|
||||
if (!rc && sensor_secure)
|
||||
/* Sensor validated by TA*/
|
||||
sensor_info[sensor_id].ready++;
|
||||
else {
|
||||
msm_camera_tz_unload_ta();
|
||||
rc = -EFAULT;
|
||||
}
|
||||
msm_camera_tz_unlock();
|
||||
}
|
||||
CDBG("Init TA %s - %s(%d) - %llu\n",
|
||||
sensor_info[sensor_id].ta_name,
|
||||
(sensor_info[sensor_id].ta_enabled)?"Ok" :
|
||||
"Failed", rc, ktime_us_delta(ktime_get(),
|
||||
startTime));
|
||||
if (!rc)
|
||||
msm_camera_tz_i2c_ctrl.secure_mode++;
|
||||
mutex_unlock(&msm_camera_tz_i2c_ctrl.lock);
|
||||
}
|
||||
} else
|
||||
rc = -EFAULT;
|
||||
CDBG("Power UP sensor = %d, %s(%d) - %lluus\n",
|
||||
sensor_id,
|
||||
(!rc)?"Ok":"Failed", rc,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
return rc;
|
||||
}
|
||||
|
||||
int32_t msm_camera_tz_i2c_power_down(
|
||||
struct msm_camera_i2c_client *client)
|
||||
{
|
||||
int32_t rc = -EFAULT;
|
||||
int32_t rc = 0;
|
||||
int32_t sensor_id = msm_camera_tz_i2c_is_sensor_secure(client);
|
||||
|
||||
if (!msm_camera_tz_i2c_ctrl.lock_ready) {
|
||||
msm_camera_tz_i2c_ctrl.lock_ready = 1;
|
||||
mutex_init(&msm_camera_tz_i2c_ctrl.lock);
|
||||
}
|
||||
ktime_t startTime = ktime_get();
|
||||
|
||||
CDBG("Enter (sensor_id=%d)\n", sensor_id);
|
||||
if ((sensor_id >= 0) && (msm_camera_tz_i2c_ctrl.secure_mode != 0)) {
|
||||
mutex_lock(&msm_camera_tz_i2c_ctrl.lock);
|
||||
if (msm_camera_tz_i2c_ctrl.secure_mode == 1) {
|
||||
ktime_t startTime = ktime_get();
|
||||
if ((sensor_id >= 0) &&
|
||||
(sensor_id < MAX_CAMERAS) &&
|
||||
(sensor_info[sensor_id].ready != 0)) {
|
||||
|
||||
CDBG("Switch to non-secure mode (secure sensor=%d)\n",
|
||||
sensor_id);
|
||||
/* Shutdown the TA */
|
||||
if (sensor_info[sensor_id].ta_qseecom_handle != NULL) {
|
||||
msm_camera_tz_i2c_ta_power_down(
|
||||
sensor_info[sensor_id].
|
||||
ta_qseecom_handle,
|
||||
sensor_id);
|
||||
rc = qseecom_shutdown_app(&sensor_info[
|
||||
sensor_id].ta_qseecom_handle);
|
||||
sensor_info[sensor_id].ta_qseecom_handle
|
||||
= EMPTY_QSEECOM_HANDLE;
|
||||
}
|
||||
CDBG("Unload TA %s - %s(%d) - %llu\n",
|
||||
sensor_info[sensor_id].ta_name,
|
||||
(!rc)?"Ok":"Failed", rc,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
}
|
||||
msm_camera_tz_i2c_ctrl.secure_mode--;
|
||||
mutex_unlock(&msm_camera_tz_i2c_ctrl.lock);
|
||||
}
|
||||
msm_camera_tz_lock();
|
||||
rc = msm_camera_tz_i2c_ta_power_down(
|
||||
msm_camera_tz_get_ta_handle(),
|
||||
sensor_id);
|
||||
sensor_info[sensor_id].ready--;
|
||||
msm_camera_tz_unlock();
|
||||
if (!sensor_info[sensor_id].ready)
|
||||
rc = msm_camera_tz_unload_ta();
|
||||
} else
|
||||
rc = -EFAULT;
|
||||
CDBG("Power DOWN sensor = %d, %s(%d) - %lluus\n",
|
||||
sensor_id,
|
||||
(!rc)?"Ok":"Failed", rc,
|
||||
ktime_us_delta(ktime_get(), startTime));
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -839,7 +628,7 @@ int32_t msm_camera_tz_i2c_read_seq(struct msm_camera_i2c_client *client,
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_READ_SEQ);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_READ_SEQ);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -885,7 +674,7 @@ int32_t msm_camera_tz_i2c_write_seq(struct msm_camera_i2c_client *client,
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_WRITE_SEQ);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_WRITE_SEQ);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -907,7 +696,7 @@ int32_t msm_camera_tz_i2c_write_table_async(
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_WRITE_TABLE_ASYNC);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE_ASYNC);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -929,7 +718,7 @@ int32_t msm_camera_tz_i2c_write_table_sync(
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_WRITE_TABLE_SYNC);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE_SYNC);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -951,7 +740,7 @@ int32_t msm_camera_tz_i2c_write_table_sync_block(
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_WRITE_TABLE_SYNC_BLOCK);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE_SYNC_BLOCK);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -974,7 +763,7 @@ int32_t msm_camera_tz_i2c_write_table(
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_WRITE_TABLE);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -996,7 +785,7 @@ int32_t msm_camera_tz_i2c_write_seq_table(
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_WRITE_SEQ_TABLE);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_WRITE_SEQ_TABLE);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -1018,7 +807,7 @@ int32_t msm_camera_tz_i2c_write_table_w_microdelay(
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_WRITE_TABLE_W_MICRODELAY);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_WRITE_TABLE_W_MICRODELAY);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -1041,7 +830,7 @@ int32_t msm_camera_tz_i2c_poll(struct msm_camera_i2c_client *client,
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_POLL);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_POLL);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
@ -1064,7 +853,7 @@ int32_t msm_camera_tz_i2c_write_conf_tbl(
|
|||
|
||||
if (sensor_id >= 0) {
|
||||
rc = msm_camera_tz_i2c_ta_cci_generic(
|
||||
client, TZ_I2C_CMD_CCI_WRITE_CONF_TBL);
|
||||
client, MSM_CAMERA_TZ_CMD_CCI_WRITE_CONF_TBL);
|
||||
msm_camera_tz_i2c_ta_done();
|
||||
}
|
||||
return TZ_I2C_FN_RETURN(rc,
|
||||
|
|
Loading…
Add table
Reference in a new issue