From patchwork Wed Aug 1 06:07:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 143242 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp456056ljj; Tue, 31 Jul 2018 23:08:07 -0700 (PDT) X-Received: by 2002:a62:3c4f:: with SMTP id j76-v6mr25481370pfa.119.1533103687139; Tue, 31 Jul 2018 23:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533103687; cv=none; d=google.com; s=arc-20160816; b=Iz7HWmIdY/uDWGF3PKAXztOIovpyZTUdOOLXDODaumDyapiuyD2NXuqZDGxlP8+wSL uSINOS/P7Ho14vHbN4Y+P6V2oIublt2WQFhtjX8Gq6iJLxM97EAk4hFFpY8K0iFSpXkt Dc0sI+ZJHle1fmZzmLgg3s70Ub1O7OfGHtzmaVax19Xmxq9AEdm+eW2QbjSg4clpbb94 w7X9E7m0F1cuj7L/mp80zzJEZfs3rED0/hEleEoglqlsAay8FkjVq/QCtp0DXnTJprCQ KoFJJy2Byb0lzx71/bM3lHyOZ8IyVcWKLg2J9NeH+p4VlcqUpYH5QZHBmyzXH7u/7Ht/ dEfA== 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=FyTN26VOgzGOdsSizLtBtuEa6l3F0o7pMIcb1iqX3fY=; b=NDNvlcxaG1BPlfNUaYDg4r5l+hlPS7PwGwMECkINALapEQjtrdui3G4R9/qjzjA8g3 z5PHYCtSLm/0EcmvqhQXkn/U23tv7GHYFnzRy+Gpolpf+UQL+f0XXdRtLene4xmIze4m JKLolOzfEUh7qFutOFq0IY5tbrPcAG6mTfnYH1FiUKu+neEMoft83vN/ufDcKt4UBhBw MhkQAXyZ1QiAAZjlIsp+M8iSVdWu3NxD069WHaFU3sPD9DCu/0Qgfie9u2exZqtFSg4p /Y8gP7ybo9RG4D4NhvsJccHApWFOFJluVZDtG1KiHXclD8bnJBLEc7tz1Lut60PmOpnX g7VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="B/tT4aqN"; 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 l7-v6sor4359576pgl.245.2018.07.31.23.08.06 for (Google Transport Security); Tue, 31 Jul 2018 23:08:07 -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="B/tT4aqN"; 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=FyTN26VOgzGOdsSizLtBtuEa6l3F0o7pMIcb1iqX3fY=; b=B/tT4aqNFiSxCQKGfbpEQa9DHPQ+dPeSmatdA03GVhko0bs67bUD6qAgVwE9ewlXqd pZTkaQKmg7zgPOeIwXmRf5U49BJW6hMrjAUm5LI+BDbXyDHowc6DbTzaIABsuB3i+3RH y4aLE0zVAQbusOoq21CiE/0HO2ewIoKDK62H4= 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=FyTN26VOgzGOdsSizLtBtuEa6l3F0o7pMIcb1iqX3fY=; b=hy8fIvL1bB8O/CG8hPW7v3escgB+I5SbERFcjVCAZv41AjOUkoBGtByHZIuqYBwP/x PSUo7eOtNBsy0c+R+OXPN6OVoraNPwGOWcatNHusxmmhX8SSnJBjImkenMnLBprJm7z2 MXlsn5F4qqJS/Lw8xbv2Rz3rjzRPGnF1OtWj9MQxLMxNywmfPHTCLH73murc/IEQ2zCu EpdrdFnDmQGpnCBiFC/FJhsfKTJ8JE7tcC9wh1ltOJKpVCTuUwSgOBjdSjneLemvwVOt Orbp3mLCDGn/fcVz5EEgrPXPBgz4mW7Ku2BJOcfwhIV6qWqDn7Klda0XPOKNk71NFK3q I0aQ== X-Gm-Message-State: AOUpUlG4EIJSn1qfLdT4r4XvvPm8jP9bFIl/ykYznYWEAbFAAaVKqAqx h1n6YpoX9CpZdCF5og0J7aYO4TMY X-Google-Smtp-Source: AAOMgpesduZJmPZ954nzUCUMddi/mQsCHUwk3JiC+6ZGyTw+coy2U0TTmMpd6wnoPLXU1nLUoK1ICA== X-Received: by 2002:a63:7a0a:: with SMTP id v10-v6mr22876770pgc.444.1533103686565; Tue, 31 Jul 2018 23:08:06 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.255.223.217]) by smtp.gmail.com with ESMTPSA id a15-v6sm23596696pfe.32.2018.07.31.23.08.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jul 2018 23:08:06 -0700 (PDT) From: Sumit Garg To: ard.biesheuvel@linaro.org, daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [edk2][v2 PATCH 1/1] ArmPkg: Add initial OpteeLib implementation Date: Wed, 1 Aug 2018 11:37:41 +0530 Message-Id: <1533103661-23806-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 | 2 ++ ArmPkg/Include/IndustryStandard/ArmStdSmc.h | 8 +++++ ArmPkg/Include/Library/OpteeLib.h | 34 +++++++++++++++++++++ ArmPkg/Library/OpteeLib/Optee.c | 47 +++++++++++++++++++++++++++++ ArmPkg/Library/OpteeLib/OpteeLib.inf | 34 +++++++++++++++++++++ 6 files changed, 126 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 Reviewed-by: Ard Biesheuvel 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..2550c4ee8a57 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 @@ -131,6 +132,7 @@ [Components.common] ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf + OpteeLib|ArmPkg/Library/OpteeLib/OpteeLib.inf ArmPkg/Filesystem/SemihostFs/SemihostFs.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..f65d8674d9b8 --- /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 + +BOOLEAN +EFIAPI +IsOpteePresent ( + VOID + ); + +#endif diff --git a/ArmPkg/Library/OpteeLib/Optee.c b/ArmPkg/Library/OpteeLib/Optee.c new file mode 100644 index 000000000000..905e0aaa5026 --- /dev/null +++ b/ArmPkg/Library/OpteeLib/Optee.c @@ -0,0 +1,47 @@ +/** @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. +**/ +BOOLEAN +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 TRUE; + } else { + return FALSE; + } +} diff --git a/ArmPkg/Library/OpteeLib/OpteeLib.inf b/ArmPkg/Library/OpteeLib/OpteeLib.inf new file mode 100644 index 000000000000..449e28287f3f --- /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 = 0x0001001A + 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] + ArmSmcLib + BaseLib + DebugLib