From patchwork Tue Jul 31 11:02:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 143181 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5181795ljj; Tue, 31 Jul 2018 04:02:45 -0700 (PDT) X-Received: by 2002:a63:e001:: with SMTP id e1-v6mr19849892pgh.380.1533034965302; Tue, 31 Jul 2018 04:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533034965; cv=none; d=google.com; s=arc-20160816; b=vs3gaM4v0SrbnZqXMblE0ZrGFLgS1DCXCzmCXu4VE5YNmxHeI9VNFIfd+oVLpF3NmP 9S16QjIFTYrYpu47Z8QX1uwm0ZoNIK+XrAAqdUhilpbwJW50mcDvcnzSNIwACXeNmVxA oEAjDziWQJIfKu6MHbXrP+4silypd07rRU81BeGQnNuI0X9JbEm6PP5CSyPws+sT5HxK NoqlWTBi7/LvqsPqqLlRJ0mqvUxpZghgbh9l72sX7g/bJnBRmLhuc1sTC1bSXP876rP4 uPebmk+vX9TwnoNwYPY1FwmOROjt9O9Vy+y0ylTGgGn1gqDrE+Vxauq4Ion+S6e+5PY5 a1yQ== 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=AItJKFSBASp3dEIGxHr+EnopmjS/gGSWY27/AW/f3iU=; b=r98V44ivBZ17KNHcHa1bsBxrmCp3Yhp8SBpngB9Wo5VihDSKgQpV/gapQ491dKT2rg 8FwO/zekTw1E0PgvXxPL+3vDbucuKwl0aFKGvIO42zM4XwQ3aWyNDBmsWxSxOvk+VRVT M73rpUtKPDuBov3+V8ZfSx+0kDv4QE1CJmW2mMnaARXHHEHPMGWibxgf5bLlSKp2YqNL TcBFx9056JiIVfyEBB3p4hRQaXMvoqH1N9/VjinIRGsxNm6sQTdsdHle+QaVzaS9loyv wacnufAjaqSwFLdRaWQz8ty5UVaWrqEBfDshnOaQT2sHJqZ2NDCA0QsKU7z4kszNTFwe 8cbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j5gidzIj; 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 z30-v6sor3319004pgk.69.2018.07.31.04.02.45 for (Google Transport Security); Tue, 31 Jul 2018 04:02:45 -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=j5gidzIj; 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=AItJKFSBASp3dEIGxHr+EnopmjS/gGSWY27/AW/f3iU=; b=j5gidzIjBZhEdgmbq+G61KaEXBm+J6FOZ47nyR25vC/dqEtQ6jlBi42e1TJNfaxDqH 3bazRXdeR+VlfMbZNcTSXLBHHnnBB/dRgzbrFerhM3KrYrdbEaJ9kWtPCDaw9ggnaIF0 ZNiSUl3Ok0ju52VhUazurzc4ZrnxHBDWS1Bmk= 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=AItJKFSBASp3dEIGxHr+EnopmjS/gGSWY27/AW/f3iU=; b=QT66oDAKnpmd3WqketrLiJ+a+iCdmvPikeRzWoTu4aawrdnE7yWNbCnCvfcig4bLVu JF+AkQiBz0dG0/ESoX4uew5tu9NAcFRfggN+kShwj9CRnB0090IrlX3Y98Z2l98GGUYn DPBu+zf8LzzantDPKpozLxP68ix2+jzBmv1YJEUba3O0lftWSZXsLqyDgxn47FsbvWWr 5ieTKOhxp20lPNVloFlhQm2t5W4SZfjBPRa9fD/FjlaaxzuWquRGBcKcU6SWUkquDHpU a/OX1fp2uJMuGmIpuXEqcItYr59qwcc/9NtdFfymS7P1cWdhLEZVkl14ftUOOqg5q7Fb a2sg== X-Gm-Message-State: AOUpUlFWSM5wjsm6/dJn4r3yt1ZiwkAn8SKtfWUq3hTswg4b96679OrQ STYIlVo53OWZXlRJgaqizIn4bBQ02UD+Ag== X-Google-Smtp-Source: AAOMgpdgvTy6m4HGGmX4Vaby5fDJv/ZOkmpFHQwnhHc2ATQDu+fP0LDSX/8Pn7SglYXFh43YDNfRfg== X-Received: by 2002:a65:6551:: with SMTP id a17-v6mr19938723pgw.132.1533034964894; Tue, 31 Jul 2018 04:02:44 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.255.223.217]) by smtp.gmail.com with ESMTPSA id e126-v6sm28240972pfg.31.2018.07.31.04.02.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jul 2018 04:02:44 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org, ard.biesheuvel@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [edk2][PATCH 1/1] ArmPkg: Add initial OpteeLib implementation Date: Tue, 31 Jul 2018 16:32:14 +0530 Message-Id: <1533034935-21530-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 This is initial version of OP-TEE library that provides api's to communicate with OP-TEE OS (Trusted OS based on ARM TrustZone) via secure monitor calls. Currently it provides basic api to detect OP-TEE presence via UID matching. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sumit Garg --- ArmPkg/ArmPkg.dec | 1 + ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Include/IndustryStandard/ArmStdSmc.h | 8 +++++ ArmPkg/Include/Library/OpteeLib.h | 34 +++++++++++++++++++++ ArmPkg/Library/OpteeLib/Optee.c | 46 +++++++++++++++++++++++++++++ ArmPkg/Library/OpteeLib/OpteeLib.inf | 34 +++++++++++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 ArmPkg/Include/Library/OpteeLib.h create mode 100644 ArmPkg/Library/OpteeLib/Optee.c create mode 100644 ArmPkg/Library/OpteeLib/OpteeLib.inf -- 2.7.4 diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 3aa229fe2ec9..84e57a0bf01c 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -41,6 +41,7 @@ [LibraryClasses.common] ArmGicArchLib|Include/Library/ArmGicArchLib.h ArmMtlLib|ArmPlatformPkg/Include/Library/ArmMtlLib.h ArmSvcLib|Include/Library/ArmSvcLib.h + OpteeLib|Include/Library/OpteeLib.h [Guids.common] gArmTokenSpaceGuid = { 0xBB11ECFE, 0x820F, 0x4968, { 0xBB, 0xA6, 0xF7, 0x6A, 0xFE, 0x30, 0x25, 0x96 } } diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 76d768126b17..4149cef335df 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -71,6 +71,7 @@ [LibraryClasses.common] ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf + OpteeLib|ArmPkg/Library/OpteeLib/OpteeLib.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf diff --git a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h index 37d079664986..a3df8e5e51de 100644 --- a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h +++ b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h @@ -111,4 +111,12 @@ #define ARM_SMC_ID_PSCI_AFFINITY_INFO_OFF 1 #define ARM_SMC_ID_PSCI_AFFINITY_INFO_ON_PENDING 2 +/* + * SMC function IDs for Trusted OS Service queries + */ +#define ARM_SMC_ID_TOS_CALL_COUNT 0xbf00ff00 +#define ARM_SMC_ID_TOS_UID 0xbf00ff01 +/* 0xbf00ff02 is reserved */ +#define ARM_SMC_ID_TOS_REVISION 0xbf00ff03 + #endif diff --git a/ArmPkg/Include/Library/OpteeLib.h b/ArmPkg/Include/Library/OpteeLib.h new file mode 100644 index 000000000000..0806d9837968 --- /dev/null +++ b/ArmPkg/Include/Library/OpteeLib.h @@ -0,0 +1,34 @@ +/** @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 + 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_H_ +#define _OPTEE_H_ + +/* + * The 'Trusted OS Call UID' is supposed to return the following UUID for + * 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 + +UINT32 +EFIAPI +IsOpteePresent ( + VOID + ); + +#endif diff --git a/ArmPkg/Library/OpteeLib/Optee.c b/ArmPkg/Library/OpteeLib/Optee.c new file mode 100644 index 000000000000..92d17df2409c --- /dev/null +++ b/ArmPkg/Library/OpteeLib/Optee.c @@ -0,0 +1,46 @@ +/** @file + Api's to communicate with OP-TEE OS (Trusted OS based on ARM TrustZone) via + secure monitor calls. + + 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. + +**/ + +#include +#include +#include +#include + +#include + +/** + Check for OP-TEE presence. +**/ +UINT32 +EFIAPI +IsOpteePresent ( + VOID + ) +{ + ARM_SMC_ARGS ArmSmcArgs; + + // Send a Trusted OS Calls UID command + ArmSmcArgs.Arg0 = ARM_SMC_ID_TOS_UID; + ArmCallSmc (&ArmSmcArgs); + + if ((ArmSmcArgs.Arg0 == OPTEE_OS_UID0) && + (ArmSmcArgs.Arg1 == OPTEE_OS_UID1) && + (ArmSmcArgs.Arg2 == OPTEE_OS_UID2) && + (ArmSmcArgs.Arg3 == OPTEE_OS_UID3)) + return 1; + else + return 0; +} diff --git a/ArmPkg/Library/OpteeLib/OpteeLib.inf b/ArmPkg/Library/OpteeLib/OpteeLib.inf new file mode 100644 index 000000000000..602716030738 --- /dev/null +++ b/ArmPkg/Library/OpteeLib/OpteeLib.inf @@ -0,0 +1,34 @@ +#/** @file +# OP-TEE lib using secure monitor calls +# +# 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = OpteeLib + FILE_GUID = BCD50D08-9568-45B2-84DF-30AE0279AD46 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = OpteeLib + +[Sources] + Optee.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib + BaseLib + ArmSmcLib