From patchwork Tue Sep 18 17:11:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 146931 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp123918ljw; Tue, 18 Sep 2018 10:11:48 -0700 (PDT) X-Received: by 2002:a24:c303:: with SMTP id s3-v6mr11960725itg.10.1537290708517; Tue, 18 Sep 2018 10:11:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537290708; cv=none; d=google.com; s=arc-20160816; b=RpVjP3kbjCBP0TyyTVVBAkw4U2vvRd2pXaknhFlRpZfDc9gptNVokWFP5HucEfgyrt qr2R7HdpBjGCVHOgWhbu1Z6UIZ5RmdxtwViz5wOGYT/SGhWhb/dJhQ7tgew/JQQKxjE5 XiXZ106qd0ieWzh4sv01C/2kNY8/n6KTww90lyhEPVsgrZcy1fbVsUfE2WVFsIxu2UFb lkt0jsF1hD8/SOXMEE2BHBmgbKo56rAY6LUtj1Dt6EP4V102qLPBsaVz+XR5xuoxHCrC Zv1evoMir/SlEK8l6UrtlVQIJwPhsWA+DLv1dXPTRB7uFx2L8E2Zm6eWS8pXnNUclq3/ IJtg== 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; bh=Jqa/VhvmugY77L6RGdTx4qye3Mg6FDRZJxITJjVgIqg=; b=cnpvnrkfeC9XHBQL8i/qbksPwuTaSwNTGztsms5FTIkiCDhAxmYap2ePD2qW9da/ZN ISeqyAggLEYDCdzc9ou65xQSA/kI68fxKRouU+75JGhy9kgHuA9wKHDBqZRqas/TGk7x poBJnxEennFjBrpEvG/5dp7waMukZTdVbDBA6yFXuxZJtiKjfyamFDNVRYuRe0F+AnU1 d8M8kfNIOQnSFYYxw1N7N68ckFg7jpsI1cGScXJ0uTpNRDJTiGf6tOUUiOsbkRjMgjY4 herQyLgJDpJ33VWUhc2/YAkZmGw6wICN8karhYIItoWf4+6MzFwCV5dK21/4PRTxgu8q vBRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aU+RgzXR; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id a190-v6sor6249158ita.107.2018.09.18.10.11.48 for (Google Transport Security); Tue, 18 Sep 2018 10:11:48 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aU+RgzXR; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.41 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=Jqa/VhvmugY77L6RGdTx4qye3Mg6FDRZJxITJjVgIqg=; b=aU+RgzXR7WhTU0Ozzz4ABzEmKkkejVjeLWRYApvoKQ2uRv0EYz+7jngs+91WsJd12H RT32PqA8UR+G+EkfSUfyTNylRhnQYgLbgyKw/eQ7oYJWFxYXjRgtLq3icKVTi7ygHQ9U RxEAx2cYHdOwhO0O6ggEma68+jJWa0ke6JBqs= 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=Jqa/VhvmugY77L6RGdTx4qye3Mg6FDRZJxITJjVgIqg=; b=KtvJHAePytIwhwhY2oPievSQvjJDHCJoJiELqg7B6RPwlopvpnJ5ruhaOVwVk4g1zO nMbQ+p4XIMjV1S74Gwm8DOdiDlFzohVmxOG2cgyne98+MXBu0Lh9p5Ez5SPMz/tx5psC Ol1OqExIjuBYuwrT2gXHn+LtZ1R/DQdSj+pE8wiq71yauoVJm6TLDmai2/kbjpkbXjhE gVpXzyAcgKw3aEHjcOBDHJAk37AXx89piK/1N8CBU6ctMSti8pnCu0S7pPlgKYT7RSra pkn0opuAv3HFQc0k3VAE7CKn+efgoijo29swBX9gGIEcDxc0rim698sLj97OO6SYxXAw AbOw== X-Gm-Message-State: APzg51C95ehH2y4+gj/8FuGz6nZXWLu1KtAaE/3AO7CiS/TpjUTVRfWC 4GIybeYLXC4FVa4GnZmky3pE7iZl X-Google-Smtp-Source: ANB0VdZBvF8abpmb7HJ8Umf47585toYdHf6Nu62DrkpbENnysm2K4ZFxhBiaYASKSHy+MwXVJA6zgA== X-Received: by 2002:a24:3985:: with SMTP id l127-v6mr462137ita.27.1537290708075; Tue, 18 Sep 2018 10:11:48 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([209.82.80.116]) by smtp.gmail.com with ESMTPSA id k62-v6sm5228398itc.21.2018.09.18.10.11.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Sep 2018 10:11:47 -0700 (PDT) From: Sumit Garg To: haojian.zhuang@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 1/1] OP-TEE use-case Date: Tue, 18 Sep 2018 10:11:30 -0700 Message-Id: <1537290690-7644-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sumit Garg Signed-off-by: Sumit Garg --- .../SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c | 48 ++++++++++++++++++++++ .../SynQuacerDtbLoaderLib.inf | 1 + 2 files changed, 49 insertions(+) -- 2.7.4 diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c index 96090c20502c..e76ba4879c09 100644 --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c @@ -20,6 +20,7 @@ #include #include #include +#include #include STATIC @@ -109,6 +110,53 @@ DtPlatformLoadDtb ( EnableDtNode (CopyDtb, "/firmware/optee"); } +/* This UUID is generated with uuidgen + the ITU-T UUID generator at http://www.itu.int/ITU-T/asn1/uuid.html */ +#define TA_TS_UUID { 0xab, 0x7a, 0x61, 0x7c, 0xb8, 0xe7, 0x4d, 0x8f, \ + 0x83, 0x01, 0xd0, 0x9b, 0x61, 0x03, 0x6b, 0x64 } + +/* The Trusted Application Function ID(s) invoked to get random numbers */ +#define TA_CMD_GET_RNG 0 + + OpteeInit (); + +#if 1 + OPTEE_OPEN_SESSION_ARG OpenSessionArg = { 0 }; + OPTEE_INVOKE_FUNC_ARG InvokeFuncArg = { 0 }; + UINT8 TaUuid[] = TA_TS_UUID; + UINT64 RngData = 0; + + memcpy (OpenSessionArg.Uuid, TaUuid, OPTEE_UUID_LEN); + OpteeOpenSession (&OpenSessionArg); + DEBUG ((EFI_D_WARN, "OP-TEE Session: 0x%X, Ret: 0x%X, RetOrigin: 0x%X\n", OpenSessionArg.Session, OpenSessionArg.Ret, OpenSessionArg.RetOrigin)); + + InvokeFuncArg.Func = TA_CMD_GET_RNG; + InvokeFuncArg.Session = OpenSessionArg.Session; + + InvokeFuncArg.Params[0].Attr = OPTEE_MSG_ATTR_TYPE_MEM_INOUT; + InvokeFuncArg.Params[0].U.Mem.BufPtr = (UINT64) &RngData; + InvokeFuncArg.Params[0].U.Mem.Size = sizeof (UINT64); + + Status = OpteeInvokeFunc (&InvokeFuncArg); + DEBUG ((EFI_D_WARN, "OP-TEE Invoke Status: 0x%X RngData: 0x%lX, Ret: 0x%X, RetOrigin: 0x%X\n", Status, RngData, InvokeFuncArg.Ret, InvokeFuncArg.RetOrigin)); + + MicroSecondDelay(16000); + + memset(&InvokeFuncArg, 0, sizeof (OPTEE_INVOKE_FUNC_ARG)); + + InvokeFuncArg.Func = TA_CMD_GET_RNG; + InvokeFuncArg.Session = OpenSessionArg.Session; + + InvokeFuncArg.Params[0].Attr = OPTEE_MSG_ATTR_TYPE_MEM_INOUT; + InvokeFuncArg.Params[0].U.Mem.BufPtr = (UINT64) &RngData; + InvokeFuncArg.Params[0].U.Mem.Size = sizeof (UINT64); + + Status = OpteeInvokeFunc (&InvokeFuncArg); + DEBUG ((EFI_D_WARN, "OP-TEE Invoke Status: 0x%X RngData: 0x%lX, Ret: 0x%X, RetOrigin: 0x%X\n", Status, RngData, InvokeFuncArg.Ret, InvokeFuncArg.RetOrigin)); + + OpteeCloseSession (OpenSessionArg.Session); +#endif + *Dtb = CopyDtb; *DtbSize = CopyDtbSize; diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.inf b/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.inf index fd21f7c376ce..ca3c5931002a 100644 --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.inf +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.inf @@ -36,6 +36,7 @@ [LibraryClasses] FdtLib MemoryAllocationLib OpteeLib + TimerLib [Pcd] gSynQuacerTokenSpaceGuid.PcdPcieEnableMask