From patchwork Tue Jul 31 10:56:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 143179 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5175887ljj; Tue, 31 Jul 2018 03:57:05 -0700 (PDT) X-Received: by 2002:a63:f18:: with SMTP id e24-v6mr20105378pgl.320.1533034624897; Tue, 31 Jul 2018 03:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533034624; cv=none; d=google.com; s=arc-20160816; b=Zs8EtangX2WEyWH/P9gwjlOKt3Fphpn7y1ligoPcqySC2HV/LzW01xYsANdkqAO0KB 2KM0/28JMKYMyIgto3CNcL/TIgidTshOxB8X7k00KI3a2GovfeI0vhLvZG/Q+stemM9Z jp9R6fkCjCSJW0LZs17ejv6YPxoRfQw+ZBo7PX8QukObK1DG4TWiK3t08oFMuwcYeZ2u /XflNqmiVOgIsxr/37TeP8aT2k0nNcn3uFPgd68ckMJ7byDmtLZsz+bX7RjN7YsViofi njBQPrEQ7Jj6lsQk2Gsvvj70h9ElcY6+la+fB3InetbV+xEnoZhhkWyRvlsBVny5FYE1 7TRg== 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=rmxF0vEqOY8711XIrGpJfKIuwUGOKR7JrEqM6olqjK6sTkffd+r69IGsNJNc0aLRSK CwNXU445WtoaJR9LJNac7iXuirz9io1uyYAcyswIADCoxnwFGJilEllPVlMRYVzU/8fa VfGoIJ4u1XfYD/nZnnAx7v/8QTUkXLcldG2fnYbeNY2CSMN/Gku3euceAMTrJK/FwgBA aMm4MrWe3cDLghLbsdhSr/xw2Z7Z65uDP7HbK2u1ELhH+Ljl8YpgVIdO1s1l1Mrqr5Ne ktXNMkG6ygyLg/J/DxFex/43A3J94oX3rATQm/wUNlVY1m/+dPI9bMnwHLxijc64g0KN FwtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d+72ydCY; 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 c2-v6sor2041734plb.4.2018.07.31.03.57.04 for (Google Transport Security); Tue, 31 Jul 2018 03:57:04 -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=d+72ydCY; 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=d+72ydCYBtml/cSb5Ex7GP++q6mfX7cf5pGxsthcWgg1GJum2zSlIaJWXgWmnx1c+q AJZnRntMpg6ntOq5oHsKBQHf4Kax3k90jobCT1qbDh1KA1Sy6sSZ/Y2QSUcwNhgYr4yn bW4i3sXanaRAsvsXA1JMexso0VOgKTs0XWVaI= 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=O3EtE2rgQPjJRNXUFCV2+EGgbzxt8hGsAJG+hCQCmXv6DOciEMcxBPXOOFT1NQzfgN WukbPPB+93uKVKkHEbptNOv9mQGABWy/ss+FEqUAR98GGuA23OcJx4UaeeHPOV8d5xOL Ohngw+OmJDJTi0LLf2WiNYHdw/vons77j9TIfZrFS0Z4YyJxgEAxbtgou8FrTWztl15m wSC3auNCPFYhHqAEZSqLQzGIAM1rbbFzWbsXABC2FnG9nemQLFW3ltivF/VHFSymDkDU XYJX5OWHwFjjADkGpngdJbElIZqXPT0E2kSI5e73l0HeN1jlFsTQFDGe45XQrDQckaVu 2LPg== X-Gm-Message-State: AOUpUlEOm3tLe5f6b2YcepUcAcar+Wvm6d5MmyU+dXxG4nGxCwU7+I/G b9chIMxTiLVkjeYcQRYCBKpwdABb X-Google-Smtp-Source: AAOMgpfYjcOynHcvWaZVK4A2t8jqa1gsV2pc4YBy7MsSlrJeVoKkCUEtHXA/MrGcmZcHp2II+dFs7Q== X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr6136179pla.285.1533034624431; Tue, 31 Jul 2018 03:57:04 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.255.223.217]) by smtp.gmail.com with ESMTPSA id p19-v6sm27847659pgh.60.2018.07.31.03.57.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jul 2018 03:57:03 -0700 (PDT) From: Sumit Garg To: sumit.garg@linaro.org Cc: patches@linaro.org Subject: [edk2][PATCH 1/1] ArmPkg: Add initial OpteeLib implementation Date: Tue, 31 Jul 2018 16:26:38 +0530 Message-Id: <1533034599-21418-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