From patchwork Fri Oct 22 11:20:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 516118 Delivered-To: patch@linaro.org Received: by 2002:ac0:bf50:0:0:0:0:0 with SMTP id o16csp957720imj; Fri, 22 Oct 2021 04:20:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSefk/kziQIQf2NSSClTQItjyeRAHMEpipOQQblLIKaQBM62FUA4yNNTLfIi2iuuZY9vO/ X-Received: by 2002:a17:906:9742:: with SMTP id o2mr14687071ejy.532.1634901621015; Fri, 22 Oct 2021 04:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634901621; cv=none; d=google.com; s=arc-20160816; b=hf+3wVpc/CCdp5HDlFc/f+ORbRMQcjz+OS+VuibJV9B7EwXgnHqQpP/KrrSLG/OIVv ACI1V+spSxekQDYO374DGbmq2Q1iOuZTdAoeQwnVEXE1h1TBajsalHhR+4iZRCH2LcN6 3ZVLf1Td9CYOxXPVC5U2op/WFNxt2QN2JoYXyh+Q+Tbpnc+xeYFZO3TKRSv1YQsBa1JR Ma4MtwrBynbaf5mSgNBAgWatJXO8p7xJIVoW06r+mwKRvRb7xSY7sIqM5OxEQoRxrXdP Dxx31a8o9hrp/5UN0oV34Y0nLLqlZrzR3m926FAIPsk+UEeTF39bWdOUgoImaIQLkoLa BxMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=2JKo1q85RZ2EA5xNP1SHyyuGLT8VM1eV3g69j6vbtcc=; b=ydCpIC4vJwJyEXU95bLuE9GnrI5wMy0XI9SJNnAFzUHya0Fkthngk3NrycAmGZd0RQ 58u6BGNDVRwSg76p/SZnr0zHtHlxJN4T3OP0futvPkpiLl95iRo1ugzjwNhnr/ZxvZF4 O2jE+SD7iqRUm2TZPi1vLhU1LowQweYjTHpIfCyWuM/q/Xl7u10LwMDR1N5/bft5Mw7r HZOQZYT26xp7UMWf7YRYtXohOsga4qGXIXFl1FhbIvovppEgCtqlA+fMelKm5XuDwl7f vjaYrnVPYzQhj+oq0R8oBV2gQ1GQvVXD2g8Mt/UmcKZ0ZWzmQW6//ON52D8xCb5NMrL7 dubQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gjB5KYDn; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id dp11si8169977ejc.3.2021.10.22.04.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 04:20:21 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gjB5KYDn; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CC6DD832E9; Fri, 22 Oct 2021 13:20:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gjB5KYDn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B03BA83461; Fri, 22 Oct 2021 13:20:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 418598326F for ; Fri, 22 Oct 2021 13:20:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x632.google.com with SMTP id i1so2442877plr.13 for ; Fri, 22 Oct 2021 04:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=2JKo1q85RZ2EA5xNP1SHyyuGLT8VM1eV3g69j6vbtcc=; b=gjB5KYDn6eQOU3EPlzdP8QMCsAQZ5lZke3jzPzX3hh4JTqERgTJx6C7S3y6E6nk1DA Jvfh+MuXZ2+bq1j/dH7Qp7VqCqQGUUkjQXFkXbVH9LC9/K9MTZg7LxO8XE+7w9FCIO7d Gdf/j9ut0qiNgbaCSq1c6HWFK0Pj5SmW2csY2cMxjjeU9cLPw33mOVF/nJAeGqhN22Bd R/3qLmp9qFnDEg5p6nsde2CsZGwRbW+LEuR4bOIpE7+t/8Z3m5MLQj740lPzpm15bHA+ Wve+fYmpUy9MtjcjJ0amSyiv/NWM33bnaZSZ/0l752KZGJb84tnZjGzQTdXgobykp4H9 hBAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2JKo1q85RZ2EA5xNP1SHyyuGLT8VM1eV3g69j6vbtcc=; b=i3686oaAAmBIGLtsfmihQMuiOQwYyR9NxRN4gGMxy3DwnXTYS1hcoB7NI4T3O+Watt TOt1O0pmzOcJWwKOyt229mCySTMWcyblU11A0T56z50gJC88/9DADAmkjrafHGgQZBZG jT8o3r8CPW98fWDZIb2bkKzNP1t+S7OnEhlYJpXm/2aOjxkdVMgqkMPmHE841nibR6lm xBb4OVa+u2oipzKv3eDGIThGIhpuZm3QyGK44NZCngnk/yhXNTmRFB4jMLhP5dCPsD9z XQEG8Z3EMP51Bv1UleOYdR/bBJoZFsIyHgwBJ3TVwP0Zyh1NypK0xQmBhAZt4L5Fa4Kk br8Q== X-Gm-Message-State: AOAM532SKLdZfyxmNThZ0JlE1zj/xqxEwCs0oIWkKj5iLKjhWfq97h1K g1sS4oTY185n0Q+kp/QuWqrusSmySwpquQ== X-Received: by 2002:a17:90a:ac03:: with SMTP id o3mr14033168pjq.130.1634901604218; Fri, 22 Oct 2021 04:20:04 -0700 (PDT) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id a3sm10759904pfv.174.2021.10.22.04.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 04:20:03 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Masahisa Kojima , Heinrich Schuchardt , Alexander Graf , Ilias Apalodimas , Simon Glass Subject: [PATCH] efi_loader: add EFI_TCG2_PROTOCOL.SubmitCommand Date: Fri, 22 Oct 2021 20:20:55 +0900 Message-Id: <20211022112056.24818-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This commit adds the EFI_TCG2_PROTOCOL.SubmitCommand required in the TCG PC Client PFP spec. SubmitCommand enables to send the raw command to the TPM device. To implement this api, tpm2_submit_command() is added into tpm-v2.c. Signed-off-by: Masahisa Kojima --- include/tpm-v2.h | 15 +++++++++++++++ lib/efi_loader/efi_tcg2.c | 37 +++++++++++++++++++++++++++++++------ lib/tpm-v2.c | 6 ++++++ 3 files changed, 52 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/include/tpm-v2.h b/include/tpm-v2.h index e6b68769f3..6b04a637ca 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -642,4 +642,19 @@ u32 tpm2_write_lock(struct udevice *dev, u32 index); */ u32 tpm2_disable_platform_hierarchy(struct udevice *dev); +/** + * submit user specified data to the TPM and get response + * + * @dev TPM device + * @sendbuf: Buffer of the data to send + * @send_size: Size of the data to send + * @recvbuf: Buffer to save the response to + * @recv_size: Pointer to the size of the response buffer + * + * Returns 0 on success (and places the number of response bytes at + * recv_size) or -ve on failure. + */ +u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, + size_t send_size, u8 *recvbuf, size_t *recv_size); + #endif /* __TPM_V2_H */ diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index da02e281e7..a0728b555e 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -1033,13 +1033,38 @@ out: * Return: status code */ static efi_status_t EFIAPI -efi_tcg2_submit_command(__maybe_unused struct efi_tcg2_protocol *this, - u32 __maybe_unused input_param_block_size, - u8 __maybe_unused *input_param_block, - u32 __maybe_unused output_param_block_size, - u8 __maybe_unused *output_param_block) +efi_tcg2_submit_command(struct efi_tcg2_protocol *this, + u32 input_param_block_size, + u8 *input_param_block, + u32 output_param_block_size, + u8 *output_param_block) { - return EFI_UNSUPPORTED; + struct udevice *dev; + efi_status_t ret; + u32 rc; + size_t resp_buf_size = output_param_block_size; + + EFI_ENTRY("%p, %u, %p, %u, %p", this, input_param_block_size, + input_param_block, output_param_block_size, output_param_block); + + if (!this || !input_param_block || !input_param_block_size) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + ret = platform_get_tpm2_device(&dev); + if (ret != EFI_SUCCESS) + goto out; + + rc = tpm2_submit_command(dev, input_param_block, input_param_block_size, + output_param_block, &resp_buf_size); + if (rc) { + ret = EFI_DEVICE_ERROR; + goto out; + } + +out: + return EFI_EXIT(ret); } /** diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 235f8c20d4..ee08948ec1 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -659,3 +659,9 @@ u32 tpm2_disable_platform_hierarchy(struct udevice *dev) return 0; } + +u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, + size_t send_size, u8 *recvbuf, size_t *recv_size) +{ + return tpm_sendrecv_command(dev, sendbuf, recvbuf, recv_size); +}