From patchwork Mon Aug 20 13:35:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 144614 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3987161ljj; Mon, 20 Aug 2018 06:35:48 -0700 (PDT) X-Received: by 2002:a17:902:b7c5:: with SMTP id v5-v6mr14541763plz.49.1534772148580; Mon, 20 Aug 2018 06:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534772148; cv=none; d=google.com; s=arc-20160816; b=Yn7arKn4OvaK280Xmvfjqkxz2n/CrdZ3+rULb9KmPhFY9w1qKwQUMmKSwYQHaN2kb4 zpDIXOcjID8DyTZBtzeRvMD5tknoiOQAJUe/c4UhRemIv9M9H7kuWYMX0OWLz896f18l +U192lDMw2A0sanR3y2EwRz34BCU9JmC2pSgiE6CArQh6P+kqsOuZrH12wALcYPz0owa LrTb61uGfWnYFKCPgZ7F+PCUUGYDENUdcMyU7mhbuo0HLhGJZZKKcIJhXSqwNSwc58Yi EZy1RwYgMSLpc9BiSS/RicRCX4ARjVdBy3YHQyW0slrfgT7M9P5Z5GYYtDihSTv9EILU IWQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=niv1X/XeWrCkaHZGG2r0pPgqAZD0t2Ksl7gSXE+bvFE=; b=KYDMVvhCM7bRomK5qtuPfMaHrIlOMRPeiEg9WyoYuMtnJSlTZ5ug6H/FbKPbFuoC1X eEhLxpqLRu4EKoWKvb/h/IPhvaLIAPL3AtoHmm4GDIgyCXoSu4L3b1DL2r0g73iXMeeC XeHqH+K6aR/t9LujEqct2uTK/QjovNxGitjDsNlxU6BaWU+fzTMp5ocnlw+a5MSGP76F FehdczC20BeqKxE7kW4KG+tXHmufXnYMEpoKc5Eh6vV3HR5i2SDcitxrphsG8Lxz2WAH Bz77g1GKY0iVzontBJMNBiGXlDzcGleuE77kmGUepjMFSpprcChRLKm0rKkRorDvIK+s iezQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ENWg1SLs; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u9-v6sor426673plz.78.2018.08.20.06.35.48 for (Google Transport Security); Mon, 20 Aug 2018 06:35:48 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ENWg1SLs; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=niv1X/XeWrCkaHZGG2r0pPgqAZD0t2Ksl7gSXE+bvFE=; b=ENWg1SLshyB0SlrObyL9cjjnF/HNxZc2qmVBEtIdVkWmn3c5YSXN/QuIiemaQxnVi0 ti0ovgeJPiPcLC/JHeKncB4AJ3Hnz75vU9tKj1JVLCAB77ZGps52wRyU6T1JMv9AsGzC cZqk8DOK4ahUXBjFgwJ6f+2srCA260S7AiokY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=niv1X/XeWrCkaHZGG2r0pPgqAZD0t2Ksl7gSXE+bvFE=; b=JkcysgkEY81qanMkBs3E4p2eMKdXXvzSW2auPc94j7QeE0QbEJqeHV6hU5qrBiWlCo x0fLuvgbN/a0DK/77E7cjcIxj+JjhU8977Gm46UoCDgF2wy4QOxQkfkf6nIrUsLk4t5l rrlM5Bec856cZdaL0Ap4Y+CO5rpcZ6zhZZoTRRhqCdX45UoX0YfnWIdpqCiXeI4bG65v HdmY0TJSwwQAUg7GXLtL7KA3ujyQBOKTaoCC/Kv6T1TDj2PHooX6LORNCxC4tn6ujnn3 B3e7CeJUzRmSclMST272dI0tWa/krN/lkFuPLcLxc85+doNlvmFlD8wVBjb6EE1S/CO8 dNGg== X-Gm-Message-State: AOUpUlG3K9JWF6IYLfPC9xTHvRRN1WsjyIDyEyKnwkUCyddD10bz5F5n 8+tUvCaMxl+bhkC8ep3KDY1LU87O X-Google-Smtp-Source: AA+uWPxYjRDTay+KxTiSojfGX89kswid+T4RH5iY3fwNbdpuV3FXwGbrJvRqzIiznu72E5wsMveFdw== X-Received: by 2002:a17:902:be0a:: with SMTP id r10-v6mr8797954pls.275.1534772148046; Mon, 20 Aug 2018 06:35:48 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.197.41.174]) by smtp.gmail.com with ESMTPSA id v23-v6sm12881514pfm.80.2018.08.20.06.35.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Aug 2018 06:35:47 -0700 (PDT) From: Sumit Garg To: ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, jens.wiklander@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 1/1] ArmPkg/OpteeLib: Add APIs to communicate with OP-TEE Date: Mon, 20 Aug 2018 19:05:19 +0530 Message-Id: <1534772119-27166-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 Add following APIs to communicate with OP-TEE static TA: 1. OpteeInit 2. OpteeOpenSession 3. OpteeCloseSession 4. OpteeInvokeFunc Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sumit Garg --- ArmPkg/Include/Library/OpteeLib.h | 102 +++++++++++ ArmPkg/Library/OpteeLib/Optee.c | 344 +++++++++++++++++++++++++++++++++++ ArmPkg/Library/OpteeLib/OpteeLib.inf | 2 + ArmPkg/Library/OpteeLib/OpteeSmc.h | 51 ++++++ 4 files changed, 499 insertions(+) create mode 100644 ArmPkg/Library/OpteeLib/OpteeSmc.h -- 2.7.4 Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
diff --git a/ArmPkg/Include/Library/OpteeLib.h b/ArmPkg/Include/Library/OpteeLib.h index f65d8674d9b8..59ae63526f58 100644 --- a/ArmPkg/Include/Library/OpteeLib.h +++ b/ArmPkg/Include/Library/OpteeLib.h @@ -25,10 +25,112 @@ #define OPTEE_OS_UID2 0xaf630002 #define OPTEE_OS_UID3 0xa5d5c51b +#define OPTEE_MSG_ATTR_TYPE_NONE 0x0 +#define OPTEE_MSG_ATTR_TYPE_VALUE_INPUT 0x1 +#define OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT 0x2 +#define OPTEE_MSG_ATTR_TYPE_VALUE_INOUT 0x3 +#define OPTEE_MSG_ATTR_TYPE_MEM_INPUT 0x9 +#define OPTEE_MSG_ATTR_TYPE_MEM_OUTPUT 0xa +#define OPTEE_MSG_ATTR_TYPE_MEM_INOUT 0xb + +#define OPTEE_MSG_ATTR_TYPE_MASK 0xff + +typedef struct { + UINT64 BufPtr; + UINT64 Size; + UINT64 ShmRef; +} OPTEE_MSG_PARAM_MEM; + +typedef struct { + UINT64 A; + UINT64 B; + UINT64 C; +} OPTEE_MSG_PARAM_VALUE; + +typedef struct { + UINT64 Attr; + union { + OPTEE_MSG_PARAM_MEM Mem; + OPTEE_MSG_PARAM_VALUE Value; + } U; +} OPTEE_MSG_PARAM; + +#define MAX_PARAMS 4 + +typedef struct { + UINT32 Cmd; + UINT32 Func; + UINT32 Session; + UINT32 CancelId; + UINT32 Pad; + UINT32 Ret; + UINT32 RetOrigin; + UINT32 NumParams; + + /* NumParams tells the actual number of element in Params */ + OPTEE_MSG_PARAM Params[MAX_PARAMS]; +} OPTEE_MSG_ARG; + +#define OPTEE_UUID_LEN 16 + +/** + * struct OPTEE_OPEN_SESSION_ARG - Open session argument + * @Uuid: [in] UUID of the Trusted Application + * @Session: [out] Session id + * @Ret: [out] Return value + * @RetOrigin [out] Origin of the return value + */ +typedef struct { + UINT8 Uuid[OPTEE_UUID_LEN]; + UINT32 Session; + UINT32 Ret; + UINT32 RetOrigin; +} OPTEE_OPEN_SESSION_ARG; + +/** + * struct OPTEE_INVOKE_FUNC_ARG - Invoke Function argument + * @Func: [in] Trusted Application function, specific to the TA + * @Session: [in] Session id + * @Ret: [out] Return value + * @RetOrigin [out] Origin of the return value + * @Params [inout] Parameters for function to be invoked + */ +typedef struct { + UINT32 Func; + UINT32 Session; + UINT32 Ret; + UINT32 RetOrigin; + OPTEE_MSG_PARAM Params[MAX_PARAMS]; +} OPTEE_INVOKE_FUNC_ARG; + BOOLEAN EFIAPI IsOpteePresent ( VOID ); +EFI_STATUS +EFIAPI +OpteeInit ( + VOID + ); + +EFI_STATUS +EFIAPI +OpteeOpenSession ( + IN OUT OPTEE_OPEN_SESSION_ARG *OpenSessionArg + ); + +EFI_STATUS +EFIAPI +OpteeCloseSession ( + IN UINT32 Session + ); + +EFI_STATUS +EFIAPI +OpteeInvokeFunc ( + IN OUT OPTEE_INVOKE_FUNC_ARG *InvokeFuncArg + ); + #endif diff --git a/ArmPkg/Library/OpteeLib/Optee.c b/ArmPkg/Library/OpteeLib/Optee.c index 574527f8b5ea..498bf0165f24 100644 --- a/ArmPkg/Library/OpteeLib/Optee.c +++ b/ArmPkg/Library/OpteeLib/Optee.c @@ -14,11 +14,19 @@ **/ +#include #include #include +#include #include #include +#include +#include +#include +#include + +STATIC OPTEE_SHARED_MEMORY_INFO OpteeShmInfo = { 0 }; /** Check for OP-TEE presence. @@ -31,6 +39,7 @@ IsOpteePresent ( { ARM_SMC_ARGS ArmSmcArgs; + memset (&ArmSmcArgs, 0, sizeof (ARM_SMC_ARGS)); // Send a Trusted OS Calls UID command ArmSmcArgs.Arg0 = ARM_SMC_ID_TOS_UID; ArmCallSmc (&ArmSmcArgs); @@ -44,3 +53,338 @@ IsOpteePresent ( return FALSE; } } + +STATIC +EFI_STATUS +OpteeShmMemRemap ( + VOID + ) +{ + ARM_SMC_ARGS ArmSmcArgs; + EFI_PHYSICAL_ADDRESS Paddr; + EFI_PHYSICAL_ADDRESS Start; + EFI_PHYSICAL_ADDRESS End; + EFI_STATUS Status; + UINTN Size; + + memset (&ArmSmcArgs, 0, sizeof (ARM_SMC_ARGS)); + ArmSmcArgs.Arg0 = OPTEE_SMC_GET_SHM_CONFIG; + + ArmCallSmc (&ArmSmcArgs); + if (ArmSmcArgs.Arg0 != OPTEE_SMC_RETURN_OK) { + DEBUG ((DEBUG_WARN, "OP-TEE shared memory not supported\n")); + return EFI_UNSUPPORTED; + } + + if (ArmSmcArgs.Arg3 != OPTEE_SMC_SHM_CACHED) { + DEBUG ((DEBUG_WARN, "OP-TEE: Only normal cached shared memory supported\n")); + return EFI_UNSUPPORTED; + } + + Start = (ArmSmcArgs.Arg1 + SIZE_4KB - 1) & ~(SIZE_4KB - 1); + End = (ArmSmcArgs.Arg1 + ArmSmcArgs.Arg2) & ~(SIZE_4KB - 1); + Paddr = Start; + Size = End - Start; + + if (Size < SIZE_4KB) { + DEBUG ((DEBUG_WARN, "OP-TEE shared memory too small\n")); + return EFI_BUFFER_TOO_SMALL; + } + + Status = ArmSetMemoryAttributes (Paddr, Size, EFI_MEMORY_WB); + if (EFI_ERROR (Status)) { + return Status; + } + + OpteeShmInfo.Base = (EFI_VIRTUAL_ADDRESS)Paddr; + OpteeShmInfo.Size = Size; + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +OpteeInit ( + VOID + ) +{ + EFI_STATUS Status; + + if (!IsOpteePresent()) { + DEBUG ((DEBUG_WARN, "OP-TEE not present\n")); + return EFI_UNSUPPORTED; + } + + Status = OpteeShmMemRemap (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "OP-TEE shared memory remap failed\n")); + return Status; + } + + return EFI_SUCCESS; +} + +/** + * OpteeCallWithArg() - Do an SMC to OP-TEE in secure world + * @Parg: physical address of message to pass to secure world + * + * Does Standard SMC to OP-TEE in secure world. + * + * Returns return code from secure world, 0 is OK + */ +STATIC +UINT32 +OpteeCallWithArg ( + IN EFI_PHYSICAL_ADDRESS Parg + ) +{ + ARM_SMC_ARGS ArmSmcArgs; + + memset (&ArmSmcArgs, 0, sizeof (ARM_SMC_ARGS)); + ArmSmcArgs.Arg0 = OPTEE_SMC_CALL_WITH_ARG; + ArmSmcArgs.Arg1 = (UINT32) (Parg >> 32); + ArmSmcArgs.Arg2 = (UINT32) Parg; + + while (TRUE) { + ArmCallSmc (&ArmSmcArgs); + + if (ArmSmcArgs.Arg0 == OPTEE_SMC_RETURN_RPC_FOREIGN_INTR) { + /* + * A foreign interrupt was raised while secure world was + * executing, since they are handled in UEFI a dummy RPC is + * performed to let UEFI take the interrupt through the normal + * vector. + */ + ArmSmcArgs.Arg0 = OPTEE_SMC_RETURN_FROM_RPC; + } else { + break; + } + } + + return ArmSmcArgs.Arg0; +} + +EFI_STATUS +EFIAPI +OpteeOpenSession ( + IN OUT OPTEE_OPEN_SESSION_ARG *OpenSessionArg + ) +{ + OPTEE_MSG_ARG *MsgArg = NULL; + + if (OpteeShmInfo.Base == 0) { + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); + return EFI_NOT_STARTED; + } + + MsgArg = (OPTEE_MSG_ARG *) OpteeShmInfo.Base; + memset(MsgArg, 0, sizeof(OPTEE_MSG_ARG)); + + MsgArg->Cmd = OPTEE_MSG_CMD_OPEN_SESSION; + + /* + * Initialize and add the meta parameters needed when opening a + * session. + */ + MsgArg->Params[0].Attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | + OPTEE_MSG_ATTR_META; + MsgArg->Params[1].Attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | + OPTEE_MSG_ATTR_META; + memcpy(&MsgArg->Params[0].U.Value, OpenSessionArg->Uuid, OPTEE_UUID_LEN); + memset(&MsgArg->Params[1].U.Value, 0, OPTEE_UUID_LEN); + MsgArg->Params[1].U.Value.C = TEE_LOGIN_PUBLIC; + + MsgArg->NumParams = 2; + + if (OpteeCallWithArg((EFI_PHYSICAL_ADDRESS) MsgArg)) { + MsgArg->Ret = TEEC_ERROR_COMMUNICATION; + MsgArg->RetOrigin = TEEC_ORIGIN_COMMS; + } + + OpenSessionArg->Session = MsgArg->Session; + OpenSessionArg->Ret = MsgArg->Ret; + OpenSessionArg->RetOrigin = MsgArg->RetOrigin; + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +OpteeCloseSession ( + IN UINT32 Session + ) +{ + OPTEE_MSG_ARG *MsgArg = NULL; + + if (OpteeShmInfo.Base == 0) { + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); + return EFI_NOT_STARTED; + } + + MsgArg = (OPTEE_MSG_ARG *) OpteeShmInfo.Base; + memset(MsgArg, 0, sizeof (OPTEE_MSG_ARG)); + + MsgArg->Cmd = OPTEE_MSG_CMD_CLOSE_SESSION; + MsgArg->Session = Session; + + OpteeCallWithArg((EFI_PHYSICAL_ADDRESS) MsgArg); + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +OpteeToMsgParam ( + OUT OPTEE_MSG_PARAM *MsgParams, + IN UINT32 NumParams, + IN OPTEE_MSG_PARAM *InParams + ) +{ + UINT32 n; + EFI_VIRTUAL_ADDRESS ParamShmAddr; + UINTN ShmSize; + UINTN Size; + + Size = roundup (sizeof (OPTEE_MSG_ARG), sizeof (UINT64)); + ParamShmAddr = OpteeShmInfo.Base + Size; + ShmSize = OpteeShmInfo.Size - Size; + + for (n = 0; n < NumParams; n++) { + CONST OPTEE_MSG_PARAM *Ip = InParams + n; + OPTEE_MSG_PARAM *Mp = MsgParams + n; + UINT32 Attr = Ip->Attr & OPTEE_MSG_ATTR_TYPE_MASK; + + switch (Attr) { + case OPTEE_MSG_ATTR_TYPE_NONE: + Mp->Attr = OPTEE_MSG_ATTR_TYPE_NONE; + memset(&Mp->U, 0, sizeof (Mp->U)); + break; + + case OPTEE_MSG_ATTR_TYPE_VALUE_INPUT: + case OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_VALUE_INOUT: + Mp->Attr = Attr; + Mp->U.Value.A = Ip->U.Value.A; + Mp->U.Value.B = Ip->U.Value.B; + Mp->U.Value.C = Ip->U.Value.C; + break; + + case OPTEE_MSG_ATTR_TYPE_MEM_INPUT: + case OPTEE_MSG_ATTR_TYPE_MEM_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_MEM_INOUT: + Mp->Attr = Attr; + + if (Ip->U.Mem.Size > ShmSize) { + return EFI_OUT_OF_RESOURCES; + } + + memcpy((VOID *) ParamShmAddr, (VOID *) Ip->U.Mem.BufPtr, Ip->U.Mem.Size); + Mp->U.Mem.BufPtr = (UINT64) ParamShmAddr; + Mp->U.Mem.Size = Ip->U.Mem.Size; + + Size = roundup (Ip->U.Mem.Size, sizeof (UINT64)); + ParamShmAddr += Size; + ShmSize -= Size; + break; + + default: + return EFI_INVALID_PARAMETER; + } + } + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +OpteeFromMsgParam ( + OUT OPTEE_MSG_PARAM *OutParams, + IN UINT32 NumParams, + IN OPTEE_MSG_PARAM *MsgParams + ) +{ + UINT32 n; + + for (n = 0; n < NumParams; n++) { + OPTEE_MSG_PARAM *Op = OutParams + n; + CONST OPTEE_MSG_PARAM *Mp = MsgParams + n; + UINT32 Attr = Mp->Attr & OPTEE_MSG_ATTR_TYPE_MASK; + + switch (Attr) { + case OPTEE_MSG_ATTR_TYPE_NONE: + Op->Attr = OPTEE_MSG_ATTR_TYPE_NONE; + memset(&Op->U, 0, sizeof (Op->U)); + break; + + case OPTEE_MSG_ATTR_TYPE_VALUE_INPUT: + case OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_VALUE_INOUT: + Op->Attr = Attr; + Op->U.Value.A = Mp->U.Value.A; + Op->U.Value.B = Mp->U.Value.B; + Op->U.Value.C = Mp->U.Value.C; + break; + + case OPTEE_MSG_ATTR_TYPE_MEM_INPUT: + case OPTEE_MSG_ATTR_TYPE_MEM_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_MEM_INOUT: + Op->Attr = Attr; + + if (Mp->U.Mem.Size > Op->U.Mem.Size) { + return EFI_BAD_BUFFER_SIZE; + } + + memcpy((VOID *) Op->U.Mem.BufPtr, (VOID *) Mp->U.Mem.BufPtr, Mp->U.Mem.Size); + Op->U.Mem.Size = Mp->U.Mem.Size; + break; + + default: + return EFI_INVALID_PARAMETER; + } + } + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +OpteeInvokeFunc ( + IN OUT OPTEE_INVOKE_FUNC_ARG *InvokeFuncArg + ) +{ + EFI_STATUS Status; + OPTEE_MSG_ARG *MsgArg = NULL; + + if (OpteeShmInfo.Base == 0) { + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); + return EFI_NOT_STARTED; + } + + MsgArg = (OPTEE_MSG_ARG *) OpteeShmInfo.Base; + memset(MsgArg, 0, sizeof(OPTEE_MSG_ARG)); + + MsgArg->Cmd = OPTEE_MSG_CMD_INVOKE_COMMAND; + MsgArg->Func = InvokeFuncArg->Func; + MsgArg->Session = InvokeFuncArg->Session; + + Status = OpteeToMsgParam(MsgArg->Params, MAX_PARAMS, InvokeFuncArg->Params); + if (Status) + return Status; + + MsgArg->NumParams = MAX_PARAMS; + + if (OpteeCallWithArg((EFI_PHYSICAL_ADDRESS) MsgArg)) { + MsgArg->Ret = TEEC_ERROR_COMMUNICATION; + MsgArg->RetOrigin = TEEC_ORIGIN_COMMS; + } + + if (OpteeFromMsgParam(InvokeFuncArg->Params, MAX_PARAMS, MsgArg->Params)) { + MsgArg->Ret = TEEC_ERROR_COMMUNICATION; + MsgArg->RetOrigin = TEEC_ORIGIN_COMMS; + } + + InvokeFuncArg->Ret = MsgArg->Ret; + InvokeFuncArg->RetOrigin = MsgArg->RetOrigin; + + return EFI_SUCCESS; +} diff --git a/ArmPkg/Library/OpteeLib/OpteeLib.inf b/ArmPkg/Library/OpteeLib/OpteeLib.inf index 5abd427379cc..e03054a7167d 100644 --- a/ArmPkg/Library/OpteeLib/OpteeLib.inf +++ b/ArmPkg/Library/OpteeLib/OpteeLib.inf @@ -23,11 +23,13 @@ [Defines] [Sources] Optee.c + OpteeSmc.h [Packages] ArmPkg/ArmPkg.dec MdePkg/MdePkg.dec [LibraryClasses] + ArmMmuLib ArmSmcLib BaseLib diff --git a/ArmPkg/Library/OpteeLib/OpteeSmc.h b/ArmPkg/Library/OpteeLib/OpteeSmc.h new file mode 100644 index 000000000000..f98a9c5b85cc --- /dev/null +++ b/ArmPkg/Library/OpteeLib/OpteeSmc.h @@ -0,0 +1,51 @@ +/** @file + OP-TEE SMC header file. + + Copyright (c) 2018, Linaro Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef _OPTEE_SMC_H_ +#define _OPTEE_SMC_H_ + +/* Returned in Arg0 only from Trusted OS functions */ +#define OPTEE_SMC_RETURN_OK 0x0 + +#define OPTEE_SMC_RETURN_FROM_RPC 0x32000003 +#define OPTEE_SMC_CALL_WITH_ARG 0x32000004 +#define OPTEE_SMC_GET_SHM_CONFIG 0xb2000007 + +#define OPTEE_SMC_SHM_CACHED 1 + +#define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR 0xffff0004 + +#define OPTEE_MSG_CMD_OPEN_SESSION 0 +#define OPTEE_MSG_CMD_INVOKE_COMMAND 1 +#define OPTEE_MSG_CMD_CLOSE_SESSION 2 + +#define OPTEE_MSG_ATTR_META 0x100 + +#define TEE_LOGIN_PUBLIC 0x0 + +/* Some Global Platform error codes used in this driver */ +#define TEEC_SUCCESS 0x00000000 +#define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006 +#define TEEC_ERROR_COMMUNICATION 0xFFFF000E +#define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C + +#define TEEC_ORIGIN_COMMS 0x00000002 + +typedef struct { + EFI_VIRTUAL_ADDRESS Base; + UINTN Size; +} OPTEE_SHARED_MEMORY_INFO; + +#endif