From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.81]) by mx.groups.io with SMTP id smtpd.web12.3152.1590057222947836608 for ; Thu, 21 May 2020 03:33:43 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N7P8SkgL; spf=pass (domain: redhat.com, ip: 207.211.31.81, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590057221; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Bmzb9UejYmcSIgbjazq28BJYv9oNJqltgTPMXyFUvw=; b=N7P8SkgLKN9XyZyDQ0bCocv4rweNGS3C+oaExQN4nJV7GpDw+354MJbSPPj5QkZEAFRXoi vnVfjxJvXV6wrimcGJXhr4x3H0JZdZp/cOfGvcsvLVgldyYJ+g2r8MtMCX7HFDTsyDDckc Fn81ADmI9WH0BC9/xIwfJsChKzXFo18= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-tYSC9l-iMECHKcN5LyQztw-1; Thu, 21 May 2020 06:33:26 -0400 X-MC-Unique: tYSC9l-iMECHKcN5LyQztw-1 Received: by mail-wm1-f72.google.com with SMTP id p24so2544006wmc.5 for ; Thu, 21 May 2020 03:33:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8Bmzb9UejYmcSIgbjazq28BJYv9oNJqltgTPMXyFUvw=; b=PK0o4VvnkDZKroe/5s3VUisZWRunhiEokcpKKNr5i5Robd8HdQApPz6SyI+8T0oz5l HbeI7SM2uLIOTFdNfIs1W5faOhIFeHwz6cxFS6F5dKwfHhbLZJ9JEAIdoV9AAkmFacmM VdW5Z/vKakRD2Zw+A6G+0Eu/ifs+2tdr8kB4sJ/N1qRw9TK+6KCVZghj42ByIDRvt/Fd EAWNETtHxrAdTW/1lu2W1n94Cbllo4dSjoKWNaU4V3wgyOlCL+rCEz975VNI8kqv9ivG R8c5StAKiZM9bXmg/R9wke6OifnfnRLug1+QxQatCx29mzPWEVRz52D14N4d9ZAQ3fCF 6f4w== X-Gm-Message-State: AOAM530O5HzJOYolsvY3hNrheiajacbI18h5FOcDQALcg4qL2DFZ3tLT HRoDEGFJEEcD3bODqWoVpKA3YY7mmxpVXncg4TmhJgX/cx8nK3jRbYI9tLbHIO32UPU1oTocCET Q/YW3ZsP6fgvU3g== X-Received: by 2002:a05:600c:2197:: with SMTP id e23mr8427094wme.162.1590057204695; Thu, 21 May 2020 03:33:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmV6zs5BX/cGZVRzlfXcMteM9Rw14n6gLLIekSQCel6QPtsgG9K3rEbsaGF3NUSZ9ItJv8pw== X-Received: by 2002:a05:600c:2197:: with SMTP id e23mr8427077wme.162.1590057204378; Thu, 21 May 2020 03:33:24 -0700 (PDT) Return-Path: Received: from [192.168.1.40] (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id t6sm6315467wma.4.2020.05.21.03.33.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2020 03:33:23 -0700 (PDT) Subject: Re: [PATCH 2/3] OvmfPkg/Tcg2ConfigPei: factor out InternalTpm12Detect() To: Laszlo Ersek , edk2-devel-groups-io Cc: Ard Biesheuvel , Eric Auger , Jordan Justen , =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , Simon Hardy , Stefan Berger References: <20200520225841.17793-1-lersek@redhat.com> <20200520225841.17793-3-lersek@redhat.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: Date: Thu, 21 May 2020 12:33:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200520225841.17793-3-lersek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 5/21/20 12:58 AM, Laszlo Ersek wrote: > Move the calls to the Tpm12RequestUseTpm() and Tpm12SubmitCommand() > Tpm12DeviceLib functions to a separate C file, so that we can override > these actions in a subsequent patch. > > This code movement requires moving the TPM_RSP_GET_TICKS / TestTpm12() > helper structure / function too. > > While at it, give the TestTpm12() function @retval / @return > documentation, plus wrap an overlong line in it. > > Functionally, this patch is a no-op. > > Cc: Ard Biesheuvel > Cc: Eric Auger > Cc: Jordan Justen > Cc: Marc-André Lureau > Cc: Philippe Mathieu-Daudé > Cc: Simon Hardy > Cc: Stefan Berger > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2728 > Signed-off-by: Laszlo Ersek > --- > OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf | 2 + > OvmfPkg/Tcg/Tcg2Config/Tpm12Support.h | 30 ++++++++ > OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c | 46 +----------- > OvmfPkg/Tcg/Tcg2Config/Tpm12Support.c | 79 ++++++++++++++++++++ > 4 files changed, 115 insertions(+), 42 deletions(-) > > diff --git a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf > index b79d0a3fb912..aa996b7da778 100644 > --- a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf > +++ b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf > @@ -21,6 +21,8 @@ [Defines] > > [Sources] > Tcg2ConfigPeim.c > + Tpm12Support.c > + Tpm12Support.h > > [Packages] > MdePkg/MdePkg.dec > diff --git a/OvmfPkg/Tcg/Tcg2Config/Tpm12Support.h b/OvmfPkg/Tcg/Tcg2Config/Tpm12Support.h > new file mode 100644 > index 000000000000..c739775d2353 > --- /dev/null > +++ b/OvmfPkg/Tcg/Tcg2Config/Tpm12Support.h > @@ -0,0 +1,30 @@ > +/** @file > + Declare the InternalTpm12Detect() function, hiding the TPM-1.2 detection > + internals. > + > + Copyright (C) 2020, Red Hat, Inc. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#ifndef TPM12_SUPPORT_H_ > +#define TPM12_SUPPORT_H_ > + > +#include > + > +/** > + Detect the presence of a TPM with interface version 1.2. > + > + @retval EFI_SUCCESS TPM-1.2 available. The Tpm12RequestUseTpm() and > + Tpm12SubmitCommand(TPM_ORD_GetTicks) operations > + (from the Tpm12DeviceLib class) have succeeded. > + > + @return Error codes propagated from Tpm12RequestUseTpm() and > + Tpm12SubmitCommand(). > +**/ > +EFI_STATUS > +InternalTpm12Detect ( > + VOID > + ); > + > +#endif // TPM12_SUPPORT_H_ > diff --git a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c > index 44abd6c541f9..cc54d95cad19 100644 > --- a/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c > +++ b/OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c > @@ -15,13 +15,13 @@ > #include > > #include > -#include > #include > #include > #include > -#include > #include > > +#include "Tpm12Support.h" > + > STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = { > (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), > &gEfiTpmDeviceSelectedGuid, > @@ -34,44 +34,6 @@ STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = { > NULL > }; > > -#pragma pack (1) > - > -typedef struct { > - TPM_RSP_COMMAND_HDR Hdr; > - TPM_CURRENT_TICKS CurrentTicks; > -} TPM_RSP_GET_TICKS; > - > -#pragma pack () > - > -/** > - Probe for the TPM for 1.2 version, by sending TPM1.2 GetTicks > - > - Sending a TPM1.2 command to a TPM2 should return a TPM1.2 > - header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e) > -**/ > -static > -EFI_STATUS > -TestTpm12 ( > - ) > -{ > - EFI_STATUS Status; > - TPM_RQU_COMMAND_HDR Command; > - TPM_RSP_GET_TICKS Response; > - UINT32 Length; > - > - Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND); > - Command.paramSize = SwapBytes32 (sizeof (Command)); > - Command.ordinal = SwapBytes32 (TPM_ORD_GetTicks); > - > - Length = sizeof (Response); > - Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response); > - if (EFI_ERROR (Status)) { > - return Status; > - } > - > - return EFI_SUCCESS; > -} > - > /** > The entry point for Tcg2 configuration driver. > > @@ -90,8 +52,8 @@ Tcg2ConfigPeimEntryPoint ( > > DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__)); > > - Status = Tpm12RequestUseTpm (); > - if (!EFI_ERROR (Status) && !EFI_ERROR (TestTpm12 ())) { > + Status = InternalTpm12Detect (); > + if (!EFI_ERROR (Status)) { > DEBUG ((DEBUG_INFO, "%a: TPM1.2 detected\n", __FUNCTION__)); > Size = sizeof (gEfiTpmDeviceInstanceTpm12Guid); > Status = PcdSetPtrS ( > diff --git a/OvmfPkg/Tcg/Tcg2Config/Tpm12Support.c b/OvmfPkg/Tcg/Tcg2Config/Tpm12Support.c > new file mode 100644 > index 000000000000..4f5a775c7a03 > --- /dev/null > +++ b/OvmfPkg/Tcg/Tcg2Config/Tpm12Support.c > @@ -0,0 +1,79 @@ > +/** @file > + Implement the InternalTpm12Detect() function on top of the Tpm12DeviceLib > + class. > + > + Copyright (C) 2020, Red Hat, Inc. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#include > +#include > + > +#include "Tpm12Support.h" > + > +#pragma pack (1) > +typedef struct { > + TPM_RSP_COMMAND_HDR Hdr; > + TPM_CURRENT_TICKS CurrentTicks; > +} TPM_RSP_GET_TICKS; > +#pragma pack () > + > +/** > + Probe for the TPM for 1.2 version, by sending TPM1.2 GetTicks > + > + Sending a TPM1.2 command to a TPM2 should return a TPM1.2 > + header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e) > + > + @retval EFI_SUCCESS TPM version 1.2 probing successful. > + > + @return Error codes propagated from Tpm12SubmitCommand(). > +**/ > +STATIC > +EFI_STATUS > +TestTpm12 ( > + ) > +{ > + EFI_STATUS Status; > + TPM_RQU_COMMAND_HDR Command; > + TPM_RSP_GET_TICKS Response; > + UINT32 Length; > + > + Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND); > + Command.paramSize = SwapBytes32 (sizeof (Command)); > + Command.ordinal = SwapBytes32 (TPM_ORD_GetTicks); > + > + Length = sizeof (Response); > + Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, > + (UINT8 *)&Response); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Detect the presence of a TPM with interface version 1.2. > + > + @retval EFI_SUCCESS TPM-1.2 available. The Tpm12RequestUseTpm() and > + Tpm12SubmitCommand(TPM_ORD_GetTicks) operations > + (from the Tpm12DeviceLib class) have succeeded. > + > + @return Error codes propagated from Tpm12RequestUseTpm() and > + Tpm12SubmitCommand(). > +**/ > +EFI_STATUS > +InternalTpm12Detect ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + > + Status = Tpm12RequestUseTpm (); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + return TestTpm12 (); > +} > Reviewed-by: Philippe Mathieu-Daude