From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.3.67; helo=eur03-am5-obe.outbound.protection.outlook.com; envelope-from=udit.kumar@nxp.com; receiver=edk2-devel@lists.01.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30067.outbound.protection.outlook.com [40.107.3.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8FAD0210F4BC2 for ; Fri, 24 Aug 2018 09:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RHC09dS996hXt2gzQ5pUbmJPFmNUm/okQoH4wgH2Yyc=; b=CQubnKAvVvaPZ+1fKnNC8RRYeuUU9X5qvjnqstfqOW2zIdH0OtXyhoEWlXv+X/HxDrmlLR/Hv703/WL+0+rwGFXQ6KpSkt1cuz9+GvIaWcmOohF9XqoVIlyVvr2TlwrVl3MdajB6nUuObybJxfVxpHC2tONQAtZUR0GwkYD97to= Received: from VI1PR04MB4640.eurprd04.prod.outlook.com (20.177.56.27) by VI1PR04MB4751.eurprd04.prod.outlook.com (20.177.48.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1059.24; Fri, 24 Aug 2018 16:20:54 +0000 Received: from VI1PR04MB4640.eurprd04.prod.outlook.com ([fe80::71e6:d77f:1276:a9f]) by VI1PR04MB4640.eurprd04.prod.outlook.com ([fe80::71e6:d77f:1276:a9f%3]) with mapi id 15.20.1059.023; Fri, 24 Aug 2018 16:20:54 +0000 From: Udit Kumar To: Sumit Garg , "edk2-devel@lists.01.org" CC: "daniel.thompson@linaro.org" , "tee-dev@lists.linaro.org" , "jens.wiklander@linaro.org" , Rod Dorris , Matteo Carlini Thread-Topic: [edk2] [PATCH 1/1] ArmPkg/OpteeLib: Add APIs to communicate with OP-TEE Thread-Index: AQHUO4vs8UuJBPvtBkWU17h3sH57t6TPFMMg Date: Fri, 24 Aug 2018 16:20:54 +0000 Message-ID: References: <1535102474-24383-1-git-send-email-sumit.garg@linaro.org> In-Reply-To: <1535102474-24383-1-git-send-email-sumit.garg@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=udit.kumar@nxp.com; x-originating-ip: [2405:204:130d:839c:75e0:837c:953:b439] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR04MB4751; 6:KZudPLPUAbVNcLh3Md/V9lmRvcr7+gf2DCILEpkVM8Ng9vQQwyRs7CrCvkT7rCKmycXshaQEhbfxKOT6HPXKlrsr6UED2lQ2fCny5QqIYChQ3Pn0TKG9ese/IhzOOzR8x+D8HlAhLKnnXbW8MyjezKVXaA4n52I/XUfN4P//JIpaoS906MABizRkS7RDBDpvLC4hu4YvBHwLBBAgksluD7mCUrptL3nsEcuN9TgGvo2m7A4rRsP7uFeg1rXM97LmV3982o/cP1Zax+AAtp28ws4J5IHimtmCOE8rid8Vhz+eicI7rQwHU1U5Z/F/X//w7nz4GWbZbI1OLbddzz7JDOd9QBDk0L1PvbWvC6qJQTHKzDgaxSVvEC1ppOyHVMTwhgsRh4Z+2CwsCJaejYoSHsGb5k16+r4DgxNTU0GgMMB5xd9iHD8ICs1+M8W6oQa2rY8M4ELG9zJvUdyoiYeDEg==; 5:xnMtP0Itv6GirgXsfI7M4ySJEIaaABfMXnW6fy3U3KEJBAWCJxUzaYioNwp23J64xpjfr28961QYkGjtLyZTHUxNe5avXspwcRFGXYvgsQRVINmDkqXoJ5WhOziaxbKPnlhJC1cGn+6YCDO046wMxTkxZYsUsRxhK99Y/tQKs5c=; 7:hAJx7hwSKnRQwAGwxjtsFyauC/hS0NNfE/n+zwgReCzCMJfmdtJ1r29XzHDiCzohen5LSP/wLZyUkaz97Q/VPD9EgZRBkV6iCWf2TxXSbgod5VhimRi4WZNH0vPHfwG+MOH1QHCQOi06JB/RKSFwWI0c3+rvWU6DESjDsxvV5eGJt3mvng0zkx2DfX+NL5wBHOdmBCN0xJ9zJrOVivNHc9FW8nsIJjr+TFDogKyXyLQhlosPRrwwWbexknst88W3 x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 62107b0a-f829-4ec8-69b7-08d609dd9123 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR04MB4751; x-ms-traffictypediagnostic: VI1PR04MB4751: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(189930954265078)(162533806227266)(1553240931313)(45079756050767); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(3231311)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201708071742011)(7699016); SRVR:VI1PR04MB4751; BCL:0; PCL:0; RULEID:; SRVR:VI1PR04MB4751; x-forefront-prvs: 07749F8C42 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(396003)(346002)(136003)(39860400002)(376002)(13464003)(189003)(199004)(6116002)(97736004)(4326008)(25786009)(6246003)(478600001)(966005)(74316002)(305945005)(16799955002)(7736002)(5660300001)(11346002)(186003)(44832011)(256004)(2900100001)(575784001)(446003)(486006)(14444005)(476003)(46003)(86362001)(106356001)(105586002)(76176011)(99286004)(7696005)(68736007)(316002)(2906002)(102836004)(6506007)(53546011)(54906003)(110136005)(14454004)(53936002)(229853002)(45080400002)(2501003)(33656002)(55016002)(8676002)(8936002)(6436002)(6306002)(9686003)(53946003)(5250100002)(81156014)(81166006)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB4751; H:VI1PR04MB4640.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: pBKrjW8yv6Mzi5bBJoVk23K77qawRvNavY+H3A7GcPcgUJKDZk9XMOW3EtYD9jc0cH7Sc1WbyEGZF/WrDk5p0K81rZVorwLmk8WZCdVPgu0nD4W5aX5fV2cyBTwFv45RbZr19lRBctoJErMUz3B2NK5OfSkMhItCKiwRVwk2oZ8GBJ57kQqBo3ahJXNgFcwmX/fiIYSf8fqtuQIAWUbsiyaJ5K1K6mvvFe606btigq4AlTelEF25hRUVLic2lOm7tZz/CQwN6weUgNG7YFJuTeOushaNXxkHWew6gC9KQgPLje23O7wNIVR1kMML56MzhnmcBgxC0UFP95d9UOLG7raxoo6qugW6GtUwhb9y7KE= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62107b0a-f829-4ec8-69b7-08d609dd9123 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Aug 2018 16:20:54.5752 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4751 Subject: Re: [PATCH 1/1] ArmPkg/OpteeLib: Add APIs to communicate with OP-TEE X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Aug 2018 16:20:59 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Sumit=20 What use case you have in mind, to interface op-tee with UEFI.=20 What ARM proposed (Matteo in cc), to run MM mode in Secure side of machine = with SPM.=20 Moreover SPD (OP-TEE) and SPM(MM mode) cannot co-exists on current arm devi= ces.=20 Then how do you see MM mode working. Regards Udit > -----Original Message----- > From: edk2-devel On Behalf Of Sumit > Garg > Sent: Friday, August 24, 2018 2:51 PM > To: edk2-devel@lists.01.org > Cc: daniel.thompson@linaro.org; tee-dev@lists.linaro.org; > jens.wiklander@linaro.org > Subject: [edk2] [PATCH 1/1] ArmPkg/OpteeLib: Add APIs to communicate > with OP-TEE >=20 > Add following APIs to communicate with OP-TEE static TA: > 1. OpteeInit > 2. OpteeOpenSession > 3. OpteeCloseSession > 4. OpteeInvokeFunc >=20 > Cc: Ard Biesheuvel > Cc: Leif Lindholm > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Sumit Garg > --- > ArmPkg/Include/Library/OpteeLib.h | 102 ++++++ > ArmPkg/Library/OpteeLib/Optee.c | 358 > +++++++++++++++++++++ > ArmPkg/Library/OpteeLib/OpteeLib.inf | 2 + > ArmPkg/Library/OpteeLib/OpteeSmc.h | 43 +++ > .../Include/IndustryStandard/GlobalPlatform.h | 60 ++-- > 5 files changed, 531 insertions(+), 34 deletions(-) create mode 100644 > ArmPkg/Library/OpteeLib/OpteeSmc.h > copy ArmPkg/Include/Library/OpteeLib.h =3D> > MdePkg/Include/IndustryStandard/GlobalPlatform.h (53%) >=20 > diff --git a/ArmPkg/Include/Library/OpteeLib.h > b/ArmPkg/Include/Library/OpteeLib.h > index f65d8674d9b8..c323f49072f8 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 >=20 > +#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 > ); >=20 > +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..2111022d3662 > 100644 > --- a/ArmPkg/Library/OpteeLib/Optee.c > +++ b/ArmPkg/Library/OpteeLib/Optee.c > @@ -14,11 +14,19 @@ >=20 > **/ >=20 > +#include > #include > +#include > #include > +#include > #include >=20 > #include > +#include > +#include > +#include > + > +STATIC OPTEE_SHARED_MEMORY_INFO OpteeShmInfo =3D { 0 }; >=20 > /** > Check for OP-TEE presence. > @@ -31,6 +39,7 @@ IsOpteePresent ( > { > ARM_SMC_ARGS ArmSmcArgs; >=20 > + ZeroMem (&ArmSmcArgs, sizeof (ARM_SMC_ARGS)); > // Send a Trusted OS Calls UID command > ArmSmcArgs.Arg0 =3D ARM_SMC_ID_TOS_UID; > ArmCallSmc (&ArmSmcArgs); > @@ -44,3 +53,352 @@ 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; > + > + ZeroMem (&ArmSmcArgs, sizeof (ARM_SMC_ARGS)); > + ArmSmcArgs.Arg0 =3D OPTEE_SMC_GET_SHM_CONFIG; > + > + ArmCallSmc (&ArmSmcArgs); > + if (ArmSmcArgs.Arg0 !=3D OPTEE_SMC_RETURN_OK) { > + DEBUG ((DEBUG_WARN, "OP-TEE shared memory not supported\n")); > + return EFI_UNSUPPORTED; > + } > + > + if (ArmSmcArgs.Arg3 !=3D OPTEE_SMC_SHM_CACHED) { > + DEBUG ((DEBUG_WARN, "OP-TEE: Only normal cached shared memory > supported\n")); > + return EFI_UNSUPPORTED; > + } > + > + Start =3D (ArmSmcArgs.Arg1 + SIZE_4KB - 1) & ~(SIZE_4KB - 1); End =3D > + (ArmSmcArgs.Arg1 + ArmSmcArgs.Arg2) & ~(SIZE_4KB - 1); Paddr =3D Start= ; > + Size =3D End - Start; > + > + if (Size < SIZE_4KB) { > + DEBUG ((DEBUG_WARN, "OP-TEE shared memory too small\n")); > + return EFI_BUFFER_TOO_SMALL; > + } > + > + Status =3D ArmSetMemoryAttributes (Paddr, Size, EFI_MEMORY_WB); if > + (EFI_ERROR (Status)) { > + return Status; > + } > + > + OpteeShmInfo.Base =3D (UINTN)Paddr; > + OpteeShmInfo.Size =3D 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 =3D OpteeShmMemRemap (); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_WARN, "OP-TEE shared memory remap failed\n")); > + return Status; > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Does Standard SMC to OP-TEE in secure world. > + > + @param[in] Parg Physical address of message to pass to secure world > + > + @return 0 on success, secure world return code otherwise > + > +**/ > +STATIC > +UINT32 > +OpteeCallWithArg ( > + IN EFI_PHYSICAL_ADDRESS Parg > + ) > +{ > + ARM_SMC_ARGS ArmSmcArgs; > + > + ZeroMem (&ArmSmcArgs, sizeof (ARM_SMC_ARGS)); > + ArmSmcArgs.Arg0 =3D OPTEE_SMC_CALL_WITH_ARG; > + ArmSmcArgs.Arg1 =3D (UINT32)(Parg >> 32); > + ArmSmcArgs.Arg2 =3D (UINT32)Parg; > + > + while (TRUE) { > + ArmCallSmc (&ArmSmcArgs); > + > + if (ArmSmcArgs.Arg0 =3D=3D 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 =3D 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; > + > + MsgArg =3D NULL; > + > + if (OpteeShmInfo.Base =3D=3D 0) { > + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); > + return EFI_NOT_STARTED; > + } > + > + MsgArg =3D (OPTEE_MSG_ARG *)OpteeShmInfo.Base; ZeroMem (MsgArg, > sizeof > + (OPTEE_MSG_ARG)); > + > + MsgArg->Cmd =3D OPTEE_MSG_CMD_OPEN_SESSION; > + > + // > + // Initialize and add the meta parameters needed when opening a // > + session. > + // > + MsgArg->Params[0].Attr =3D OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | > + OPTEE_MSG_ATTR_META; MsgArg->Params[1].Attr > + =3D OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | > + OPTEE_MSG_ATTR_META; CopyMem > + (&MsgArg->Params[0].U.Value, OpenSessionArg->Uuid, OPTEE_UUID_LEN); > + ZeroMem (&MsgArg->Params[1].U.Value, OPTEE_UUID_LEN); > + MsgArg->Params[1].U.Value.C =3D TEE_LOGIN_PUBLIC; > + > + MsgArg->NumParams =3D 2; > + > + if (OpteeCallWithArg ((EFI_PHYSICAL_ADDRESS)MsgArg)) { > + MsgArg->Ret =3D TEEC_ERROR_COMMUNICATION; > + MsgArg->RetOrigin =3D TEEC_ORIGIN_COMMS; } > + > + OpenSessionArg->Session =3D MsgArg->Session; OpenSessionArg->Ret =3D > + MsgArg->Ret; OpenSessionArg->RetOrigin =3D MsgArg->RetOrigin; > + > + return EFI_SUCCESS; > +} > + > +EFI_STATUS > +EFIAPI > +OpteeCloseSession ( > + IN UINT32 Session > + ) > +{ > + OPTEE_MSG_ARG *MsgArg; > + > + MsgArg =3D NULL; > + > + if (OpteeShmInfo.Base =3D=3D 0) { > + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); > + return EFI_NOT_STARTED; > + } > + > + MsgArg =3D (OPTEE_MSG_ARG *)OpteeShmInfo.Base; ZeroMem (MsgArg, > sizeof > + (OPTEE_MSG_ARG)); > + > + MsgArg->Cmd =3D OPTEE_MSG_CMD_CLOSE_SESSION; MsgArg->Session =3D > + 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 Idx; > + UINTN ParamShmAddr; > + UINTN ShmSize; > + UINTN Size; > + > + Size =3D (sizeof (OPTEE_MSG_ARG) + sizeof (UINT64) - 1) & ~(sizeof > + (UINT64) - 1); ParamShmAddr =3D OpteeShmInfo.Base + Size; ShmSize =3D > + OpteeShmInfo.Size - Size; > + > + for (Idx =3D 0; Idx < NumParams; Idx++) { > + CONST OPTEE_MSG_PARAM *Ip; > + OPTEE_MSG_PARAM *Mp; > + UINT32 Attr; > + > + Ip =3D InParams + Idx; > + Mp =3D MsgParams + Idx; > + Attr =3D Ip->Attr & OPTEE_MSG_ATTR_TYPE_MASK; > + > + switch (Attr) { > + case OPTEE_MSG_ATTR_TYPE_NONE: > + Mp->Attr =3D OPTEE_MSG_ATTR_TYPE_NONE; > + ZeroMem (&Mp->U, 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 =3D Attr; > + Mp->U.Value.A =3D Ip->U.Value.A; > + Mp->U.Value.B =3D Ip->U.Value.B; > + Mp->U.Value.C =3D 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 =3D Attr; > + > + if (Ip->U.Mem.Size > ShmSize) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + CopyMem ((VOID *)ParamShmAddr, (VOID *)Ip->U.Mem.BufPtr, Ip- > >U.Mem.Size); > + Mp->U.Mem.BufPtr =3D (UINT64)ParamShmAddr; > + Mp->U.Mem.Size =3D Ip->U.Mem.Size; > + > + Size =3D (Ip->U.Mem.Size + sizeof (UINT64) - 1) & ~(sizeof (UINT64= ) - 1); > + ParamShmAddr +=3D Size; > + ShmSize -=3D 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 Idx; > + > + for (Idx =3D 0; Idx < NumParams; Idx++) { > + OPTEE_MSG_PARAM *Op; > + CONST OPTEE_MSG_PARAM *Mp; > + UINT32 Attr; > + > + Op =3D OutParams + Idx; > + Mp =3D MsgParams + Idx; > + Attr =3D Mp->Attr & OPTEE_MSG_ATTR_TYPE_MASK; > + > + switch (Attr) { > + case OPTEE_MSG_ATTR_TYPE_NONE: > + Op->Attr =3D OPTEE_MSG_ATTR_TYPE_NONE; > + ZeroMem (&Op->U, 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 =3D Attr; > + Op->U.Value.A =3D Mp->U.Value.A; > + Op->U.Value.B =3D Mp->U.Value.B; > + Op->U.Value.C =3D 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 =3D Attr; > + > + if (Mp->U.Mem.Size > Op->U.Mem.Size) { > + return EFI_BAD_BUFFER_SIZE; > + } > + > + CopyMem ((VOID *)Op->U.Mem.BufPtr, (VOID *)Mp->U.Mem.BufPtr, > Mp->U.Mem.Size); > + Op->U.Mem.Size =3D 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; > + > + MsgArg =3D NULL; > + > + if (OpteeShmInfo.Base =3D=3D 0) { > + DEBUG ((DEBUG_WARN, "OP-TEE not initialized\n")); > + return EFI_NOT_STARTED; > + } > + > + MsgArg =3D (OPTEE_MSG_ARG *)OpteeShmInfo.Base; ZeroMem (MsgArg, > sizeof > + (OPTEE_MSG_ARG)); > + > + MsgArg->Cmd =3D OPTEE_MSG_CMD_INVOKE_COMMAND; MsgArg->Func =3D > + InvokeFuncArg->Func; MsgArg->Session =3D InvokeFuncArg->Session; > + > + Status =3D OpteeToMsgParam (MsgArg->Params, MAX_PARAMS, > + InvokeFuncArg->Params); if (Status) > + return Status; > + > + MsgArg->NumParams =3D MAX_PARAMS; > + > + if (OpteeCallWithArg ((EFI_PHYSICAL_ADDRESS)MsgArg)) { > + MsgArg->Ret =3D TEEC_ERROR_COMMUNICATION; > + MsgArg->RetOrigin =3D TEEC_ORIGIN_COMMS; } > + > + if (OpteeFromMsgParam (InvokeFuncArg->Params, MAX_PARAMS, > MsgArg->Params)) { > + MsgArg->Ret =3D TEEC_ERROR_COMMUNICATION; > + MsgArg->RetOrigin =3D TEEC_ORIGIN_COMMS; } > + > + InvokeFuncArg->Ret =3D MsgArg->Ret; > + InvokeFuncArg->RetOrigin =3D 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] >=20 > [Sources] > Optee.c > + OpteeSmc.h >=20 > [Packages] > ArmPkg/ArmPkg.dec > MdePkg/MdePkg.dec >=20 > [LibraryClasses] > + ArmMmuLib > ArmSmcLib > BaseLib > diff --git a/ArmPkg/Library/OpteeLib/OpteeSmc.h > b/ArmPkg/Library/OpteeLib/OpteeSmc.h > new file mode 100644 > index 000000000000..e2ea35784a0a > --- /dev/null > +++ b/ArmPkg/Library/OpteeLib/OpteeSmc.h > @@ -0,0 +1,43 @@ > +/** @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 > + > + > https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fope > n > + source.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cudit.kumar% > + > 40nxp.com%7Ce95635d0c3c74edbf79808d609a30c7b%7C686ea1d3bc2b4c6f > a92cd99 > + > c5c301635%7C0%7C0%7C636706993250535371&sdata=3DpyZF9Ku3qEpp > OOKCyshbg > + 9oCT4P6AwM2olKY3%2B2ImWs%3D&reserved=3D0 > + > + 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 > + > +typedef struct { > + UINTN Base; > + UINTN Size; > +} OPTEE_SHARED_MEMORY_INFO; > + > +#endif > diff --git a/ArmPkg/Include/Library/OpteeLib.h > b/MdePkg/Include/IndustryStandard/GlobalPlatform.h > similarity index 53% > copy from ArmPkg/Include/Library/OpteeLib.h copy to > MdePkg/Include/IndustryStandard/GlobalPlatform.h > index f65d8674d9b8..14c621d89971 100644 > --- a/ArmPkg/Include/Library/OpteeLib.h > +++ b/MdePkg/Include/IndustryStandard/GlobalPlatform.h > @@ -1,34 +1,26 @@ > -/** @file > - OP-TEE specific 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 > - > https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fope > nsource.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cudit.kumar%40nxp.com%7Ce95635d0c > 3c74edbf79808d609a30c7b%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0% > 7C0%7C636706993250535371&sdata=3DpyZF9Ku3qEppOOKCyshbg9oCT4 > P6AwM2olKY3%2B2ImWs%3D&reserved=3D0 > - > - 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_H_ > -#define _OPTEE_H_ > - > -/* > - * The 'Trusted OS Call UID' is supposed to return the following UUID fo= r > - * OP-TEE OS. This is a 128-bit value. > - */ > -#define OPTEE_OS_UID0 0x384fb3e0 > -#define OPTEE_OS_UID1 0xe7f811e3 > -#define OPTEE_OS_UID2 0xaf630002 > -#define OPTEE_OS_UID3 0xa5d5c51b > - > -BOOLEAN > -EFIAPI > -IsOpteePresent ( > - VOID > - ); > - > -#endif > +/** @file > + Standardized Global Platform 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 > + > + > https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fope > n > + source.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cudit.kumar% > + > 40nxp.com%7Ce95635d0c3c74edbf79808d609a30c7b%7C686ea1d3bc2b4c6f > a92cd99 > + > c5c301635%7C0%7C0%7C636706993250535371&sdata=3DpyZF9Ku3qEpp > OOKCyshbg > + 9oCT4P6AwM2olKY3%2B2ImWs%3D&reserved=3D0 > + > + 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 _GLOBAL_PLATFORM_H_ > +#define _GLOBAL_PLATFORM_H_ > + > +#define TEEC_ORIGIN_COMMS 0x00000002 > + > +#define TEEC_SUCCESS 0x00000000 > +#define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006 > +#define TEEC_ERROR_COMMUNICATION 0xFFFF000E > +#define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C > + > +#endif > -- > 2.7.4 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://emea01.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Flist > s.01.org%2Fmailman%2Flistinfo%2Fedk2- > devel&data=3D02%7C01%7Cudit.kumar%40nxp.com%7Ce95635d0c3c74e > dbf79808d609a30c7b%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0% > 7C636706993250535371&sdata=3DmsA6jGRAkpWoQ33VsDfbWqgGcIMTP > u%2Fhcds3j9aDPnU%3D&reserved=3D0