lib: optee_client: update to new optee msg for optee v1 platform
optee v1 smc message is deprecated and update to new optee msg, api revision smc call is add in init func to check capcibility. Change-Id: Ia54a1257050b5e3776a00b6b76ca608c939bb401 Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com> Signed-off-by: Elon Zhang <zhangzj@rock-chips.com>
This commit is contained in:
parent
102dfafc4a
commit
74eb602743
|
|
@ -647,19 +647,6 @@ struct teesmc_meta_open_session {
|
|||
|
||||
typedef struct teesmc_meta_open_session t_teesmc_meta_open_session;
|
||||
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
|
||||
typedef struct teesmc32_arg t_teesmc32_arg;
|
||||
typedef struct teesmc32_param t_teesmc32_param;
|
||||
|
||||
#define TEESMC32_GET_PARAMS(x) \
|
||||
(struct teesmc32_param *)(((struct teesmc32_arg *)(x)) + 1)
|
||||
|
||||
#define TEESMC32_GET_ARG_SIZE(num_params) \
|
||||
(sizeof(struct teesmc32_arg) + \
|
||||
sizeof(struct teesmc32_param) * (num_params))
|
||||
|
||||
#endif
|
||||
void tee_smc_call(ARM_SMC_ARGS *param);
|
||||
|
||||
#endif /* TEESMC_H */
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ struct optee_msg_arg_v2 {
|
|||
struct optee_msg_param_v2 params[];
|
||||
};
|
||||
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
typedef struct optee_msg_arg_v2 t_teesmc32_arg;
|
||||
typedef struct optee_msg_param_v2 t_teesmc32_param;
|
||||
|
||||
|
|
@ -61,8 +60,6 @@ typedef struct optee_msg_param_v2 t_teesmc32_param;
|
|||
#define TEESMC32_GET_PARAMS(x) \
|
||||
(struct optee_msg_param_v2 *)(((struct optee_msg_arg_v2 *)(x)) + 1)
|
||||
|
||||
#endif
|
||||
|
||||
#define OPTEE_MSG_ATTR_TYPE_NONE_V2 0x0
|
||||
#define OPTEE_MSG_ATTR_TYPE_VALUE_INPUT_V2 0x1
|
||||
#define OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT_V2 0x2
|
||||
|
|
@ -96,11 +93,18 @@ typedef struct optee_msg_param_v2 t_teesmc32_param;
|
|||
#define OPTEE_SMC_FUNC_MASK_V2 0xFFFF
|
||||
|
||||
#define OPTEE_SMC_OWNER_TRUSTED_OS_V2 50
|
||||
#define OPTEE_SMC_OWNER_TRUSTED_OS_API 63
|
||||
|
||||
#define OPTEE_SMC_FUNCID_GET_SHM_CONFIG_V2 7
|
||||
#define OPTEE_SMC_GET_SHM_CONFIG_V2 \
|
||||
OPTEE_SMC_FAST_CALL_VAL_V2(OPTEE_SMC_FUNCID_GET_SHM_CONFIG_V2)
|
||||
|
||||
#define OPTEE_SMC_FUNCID_CALLS_REVISION 0xFF03
|
||||
#define OPTEE_SMC_CALLS_REVISION \
|
||||
OPTEE_SMC_CALL_VAL_V2(OPTEE_SMC_32_V2, OPTEE_SMC_FAST_CALL_V2, \
|
||||
OPTEE_SMC_OWNER_TRUSTED_OS_API, \
|
||||
OPTEE_SMC_FUNCID_CALLS_REVISION)
|
||||
|
||||
#define OPTEE_SMC_FAST_CALL_VAL_V2(func_num) \
|
||||
OPTEE_SMC_CALL_VAL_V2(OPTEE_SMC_32_V2, OPTEE_SMC_FAST_CALL_V2, \
|
||||
OPTEE_SMC_OWNER_TRUSTED_OS_V2, (func_num))
|
||||
|
|
|
|||
|
|
@ -7,8 +7,35 @@
|
|||
#include <common.h>
|
||||
#include <optee_include/OpteeClientApiLib.h>
|
||||
#include <optee_include/OpteeClientMem.h>
|
||||
#include <optee_include/OpteeClientRPC.h>
|
||||
#include <optee_include/OpteeClientSMC.h>
|
||||
#include <optee_include/OpteeClientRkFs.h>
|
||||
#include <optee_include/teesmc.h>
|
||||
#include <optee_include/teesmc_optee.h>
|
||||
#include <optee_include/teesmc_v2.h>
|
||||
|
||||
#define OPTEE_MSG_REVISION_MAJOR 2
|
||||
#define OPTEE_MSG_REVISION_MINOR 0
|
||||
|
||||
static bool optee_api_revision_is_compatible(void)
|
||||
{
|
||||
ARM_SMC_ARGS ArmSmcArgs = {0};
|
||||
|
||||
ArmSmcArgs.Arg0 = OPTEE_SMC_CALLS_REVISION;
|
||||
|
||||
tee_smc_call(&ArmSmcArgs);
|
||||
|
||||
if (ArmSmcArgs.Arg0 == OPTEE_MSG_REVISION_MAJOR &&
|
||||
ArmSmcArgs.Arg1 >= OPTEE_MSG_REVISION_MINOR) {
|
||||
printf("optee api revision: %d.%d\n",
|
||||
ArmSmcArgs.Arg0, ArmSmcArgs.Arg1);
|
||||
return true;
|
||||
} else {
|
||||
printf("optee check api revision fail: %d.%d\n",
|
||||
ArmSmcArgs.Arg0, ArmSmcArgs.Arg1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initlialize the library
|
||||
|
|
@ -17,6 +44,10 @@ TEEC_Result OpteeClientApiLibInitialize(void)
|
|||
{
|
||||
TEEC_Result status = TEEC_SUCCESS;
|
||||
|
||||
/* check api revision compatibility */
|
||||
if (!optee_api_revision_is_compatible())
|
||||
panic("optee api revision is too low");
|
||||
|
||||
status = OpteeClientMemInit();
|
||||
if (status != TEEC_SUCCESS) {
|
||||
printf("TEEC: OpteeClientMemInit fail!\n");
|
||||
|
|
|
|||
|
|
@ -143,12 +143,7 @@ int OpteeClientMemInit(void)
|
|||
{
|
||||
ARM_SMC_ARGS ArmSmcArgs = {0};
|
||||
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
ArmSmcArgs.Arg0 = TEESMC32_OPTEE_FASTCALL_GET_SHM_CONFIG;
|
||||
#endif
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
ArmSmcArgs.Arg0 = OPTEE_SMC_GET_SHM_CONFIG_V2;
|
||||
#endif
|
||||
|
||||
tee_smc_call(&ArmSmcArgs);
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,6 @@ Exit:
|
|||
return TeecResult;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
TEEC_Result OpteeRpcCmdLoadV2Ta(t_teesmc32_arg *TeeSmc32Arg)
|
||||
{
|
||||
TEEC_Result TeecResult = TEEC_SUCCESS;
|
||||
|
|
@ -175,8 +174,8 @@ TEEC_Result OpteeRpcCmdLoadV2Ta(t_teesmc32_arg *TeeSmc32Arg)
|
|||
/*memcpy((void *)(size_t)TeeSmc32Param[1].u.memref.buf_ptr,
|
||||
(void *)keymaster_data, TeeSmc32Param[1].u.memref.size);*/
|
||||
debug("TEEC: memref.buf_ptr = 0x%llx; memref.size = 0x%llx\n",
|
||||
TeeSmc32Param[1].u.memref.buf_ptr,
|
||||
TeeSmc32Param[1].u.memref.size);
|
||||
(uint64_t)TeeSmc32Param[1].u.memref.buf_ptr,
|
||||
(uint64_t)TeeSmc32Param[1].u.memref.size);
|
||||
}
|
||||
|
||||
Exit:
|
||||
|
|
@ -187,7 +186,6 @@ Exit:
|
|||
|
||||
return TeecResult;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Free a previously loaded TA and release the memory
|
||||
|
|
@ -559,16 +557,11 @@ TEEC_Result OpteeRpcCallback(ARM_SMC_ARGS *ArmSmcArgs)
|
|||
|
||||
switch (TEESMC_RETURN_GET_RPC_FUNC(ArmSmcArgs->Arg0)) {
|
||||
case TEESMC_RPC_FUNC_ALLOC_ARG: {
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
TeecResult = OpteeRpcAlloc(ArmSmcArgs->Arg1, &ArmSmcArgs->Arg1);
|
||||
#endif
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
debug("TEEC: ArmSmcArgs->Arg1 = 0x%x \n", ArmSmcArgs->Arg1);
|
||||
TeecResult = OpteeRpcAlloc(ArmSmcArgs->Arg1, &ArmSmcArgs->Arg2);
|
||||
ArmSmcArgs->Arg5 = ArmSmcArgs->Arg2;
|
||||
ArmSmcArgs->Arg1 = 0;
|
||||
ArmSmcArgs->Arg4 = 0;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -578,12 +571,7 @@ TEEC_Result OpteeRpcCallback(ARM_SMC_ARGS *ArmSmcArgs)
|
|||
}
|
||||
|
||||
case TEESMC_RPC_FUNC_FREE_ARG: {
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
TeecResult = OpteeRpcFree(ArmSmcArgs->Arg1);
|
||||
#endif
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
TeecResult = OpteeRpcFree(ArmSmcArgs->Arg2);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -597,49 +585,10 @@ TEEC_Result OpteeRpcCallback(ARM_SMC_ARGS *ArmSmcArgs)
|
|||
}
|
||||
|
||||
case TEESMC_RPC_FUNC_CMD: {
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
t_teesmc32_arg *TeeSmc32Arg =
|
||||
(t_teesmc32_arg *)(size_t)ArmSmcArgs->Arg1;
|
||||
#endif
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
t_teesmc32_arg *TeeSmc32Arg =
|
||||
(t_teesmc32_arg *)(size_t)((uint64_t)ArmSmcArgs->Arg1 << 32 | ArmSmcArgs->Arg2);
|
||||
debug("TEEC: TeeSmc32Arg->cmd = 0x%x\n", TeeSmc32Arg->cmd);
|
||||
#endif
|
||||
switch (TeeSmc32Arg->cmd) {
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
case TEE_RPC_LOAD_TA: {
|
||||
TeecResult = OpteeRpcCmdLoadTa(TeeSmc32Arg);
|
||||
break;
|
||||
}
|
||||
|
||||
case TEE_RPC_FREE_TA: {
|
||||
TeecResult = OpteeRpcCmdFreeTa(TeeSmc32Arg);
|
||||
break;
|
||||
}
|
||||
|
||||
case TEE_RPC_RPMB_CMD: {
|
||||
TeecResult = OpteeRpcCmdRpmb(TeeSmc32Arg);
|
||||
break;
|
||||
}
|
||||
|
||||
case TEE_RPC_FS: {
|
||||
TeecResult = OpteeRpcCmdFs(TeeSmc32Arg);
|
||||
TeeSmc32Arg->ret = TEEC_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
case TEE_RPC_GET_TIME: {
|
||||
TeecResult = OpteeRpcCmdGetTime(TeeSmc32Arg);
|
||||
break;
|
||||
}
|
||||
|
||||
case TEE_RPC_WAIT_MUTEX: {
|
||||
TeecResult = OpteeRpcCmdWaitMutex(TeeSmc32Arg);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
case OPTEE_MSG_RPC_CMD_SHM_ALLOC_V2: {
|
||||
uint32_t tempaddr;
|
||||
uint32_t allocsize = TeeSmc32Arg->params[0].u.value.b;
|
||||
|
|
@ -671,7 +620,6 @@ TEEC_Result OpteeRpcCallback(ARM_SMC_ARGS *ArmSmcArgs)
|
|||
TeecResult = OpteeRpcCmdLoadV2Ta(TeeSmc32Arg);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
default: {
|
||||
printf("TEEC: ...unsupported RPC CMD: cmd=0x%X\n",
|
||||
|
|
|
|||
|
|
@ -56,13 +56,7 @@ TEEC_Result TEEC_SMC_OpenSession(TEEC_Context *context,
|
|||
|
||||
t_teesmc_meta_open_session *TeeSmcMetaSession = NULL;
|
||||
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
uint32_t MetaNum = 1;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
uint32_t MetaNum = 2;
|
||||
#endif
|
||||
|
||||
*error_origin = TEEC_ORIGIN_API;
|
||||
|
||||
|
|
@ -104,27 +98,20 @@ TEEC_Result TEEC_SMC_OpenSession(TEEC_Context *context,
|
|||
TeeSmc32Param[0].u.memref.size = sizeof(*TeeSmcMetaSession);
|
||||
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
#ifdef CONFIG_ARM64
|
||||
TeeSmc32Param[0].attr = TEESMC_ATTR_TYPE_MEMREF_INPUT |
|
||||
TEESMC_ATTR_META |
|
||||
TEEC_SMC_DEFAULT_CACHE_ATTRIBUTES;
|
||||
#else
|
||||
TeeSmc32Param[0].attr = TEESMC_ATTR_TYPE_MEMREF_INPUT |
|
||||
TEESMC_ATTR_META;
|
||||
#endif
|
||||
memcpy((void *)&TeeSmc32Param[0].u.value, &TeeSmcMetaSession->uuid, sizeof(TeeSmcMetaSession->uuid));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
uint8_t * session_uuid = (uint8_t *)&TeeSmcMetaSession->uuid;
|
||||
tee_uuid_to_octets(session_uuid, destination);
|
||||
memcpy((void *)&TeeSmc32Param[0].u.value, &TeeSmcMetaSession->uuid, sizeof(TeeSmcMetaSession->uuid));
|
||||
#endif
|
||||
TeeSmc32Param[1].u.value.c = TeeSmcMetaSession->clnt_login;
|
||||
|
||||
TeeSmc32Param[0].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT_V2 |
|
||||
OPTEE_MSG_ATTR_META_V2;
|
||||
TeeSmc32Param[1].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT_V2 |
|
||||
OPTEE_MSG_ATTR_META_V2;
|
||||
#endif
|
||||
|
||||
SetTeeSmc32Params(operation, TeeSmc32Param + MetaNum);
|
||||
|
||||
|
|
@ -293,19 +280,8 @@ void SetTeeSmc32Params(TEEC_Operation *operation,
|
|||
attr == TEEC_MEMREF_TEMP_OUTPUT ||
|
||||
attr == TEEC_MEMREF_TEMP_INOUT) {
|
||||
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
#ifdef CONFIG_ARM64
|
||||
attr |= TEEC_SMC_DEFAULT_CACHE_ATTRIBUTES;
|
||||
debug("TEEC: OPTEE_OS_V1 ARCH64 attr %x\n", attr);
|
||||
#else
|
||||
debug("TEEC: OPTEE_OS_V1 ARCH32 attr %x\n", attr);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
attr += (OPTEE_MSG_ATTR_TYPE_TMEM_INPUT_V2 - TEEC_MEMREF_TEMP_INPUT);
|
||||
debug("TEEC: OPTEE_OS_V2 ARCH64 attr %x\n", attr);
|
||||
#endif
|
||||
|
||||
TeeSmc32Param[ParamCount].attr = attr;
|
||||
TeeSmc32Param[ParamCount].u.memref.buf_ptr =
|
||||
|
|
@ -355,16 +331,9 @@ TEEC_Result OpteeSmcCall(t_teesmc32_arg *TeeSmc32Arg)
|
|||
TEEC_Result TeecResult = TEEC_SUCCESS;
|
||||
ARM_SMC_ARGS ArmSmcArgs = {0};
|
||||
|
||||
#ifdef CONFIG_OPTEE_V1
|
||||
ArmSmcArgs.Arg0 = TEESMC32_CALL_WITH_ARG;
|
||||
ArmSmcArgs.Arg1 = (uint32_t) (size_t)TeeSmc32Arg;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_OPTEE_V2
|
||||
ArmSmcArgs.Arg0 = OPTEE_SMC_CALL_WITH_ARG_V2;
|
||||
ArmSmcArgs.Arg1 = 0;
|
||||
ArmSmcArgs.Arg2 = (uint32_t) (size_t)TeeSmc32Arg;
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
tee_smc_call(&ArmSmcArgs);
|
||||
|
|
|
|||
Loading…
Reference in New Issue