From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.92.41.92]) by mx.groups.io with SMTP id smtpd.web10.18115.1611690455489676193 for ; Tue, 26 Jan 2021 11:47:35 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=VOV1iH08; spf=pass (domain: outlook.com, ip: 40.92.41.92, mailfrom: kun.q@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g9sE1SCS7tFlbdK+5CmF1iG6jepZX2UZHM0qIVLxZ3mpAu+1EroSN3vDtdzkwQxvCMsGA7+QIkhzKtnOkQXnD01aPaIKhGHcklIW31vNp8dexOr2XH9YkgNmUEl0BmkM61DpOS5EophmHzyXIjXNDNBjLZ0j+3aOYYIagOTihi46uJAmKMR4E1u+VqFWvJQ4bGQQRaG4O4pU8urkZ5mGmoLiMqWZpja9yBUxHO65oSrzled0UIw9ac6ETaDmvNFIIs75VMYMO94CmSD/Gm6opSVZXAUz/FnUJqull9R38jPNGoO8U1IEX/J5wlbzc5ckQIWmgmpEcru2++PYI4OSdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5fipUJEkDNfv/Nzb6J/qwlhRl/PjQYiqz3mVv6hUPYg=; b=ZMA+cWCSsSN1FQukeQcwlG4aZ2GrYS1oTma4f9eQ1gTYZpvQcFa1LiwGEzzDvKicjPpd5/pbcRR/nl7faKKH6Y9x0ue3vSyJqqDspxjPf5E78Hj7VYx/CirkqvDqZ7oYuNBtC6KJn+DaLoh7GPJMSkqt6Ej4VBNsfvI+zw2Gin88HT16DYmAOmTp++nEHABea0Jx/tSE+2oRPwggBsl0Cwrp4B28u3Q2bsIL0PdY+AisKcRQ+r7B0fF1GNh1JCGYn+ZJDmg1AjJEXaBBlMVLyubed+eYmW0J07xlsAse8kl28ae3vTR905MQHofw7DSNP257d4nPQFQYTxZXVbofPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5fipUJEkDNfv/Nzb6J/qwlhRl/PjQYiqz3mVv6hUPYg=; b=VOV1iH084hzzvykwytws6NtceF2ah4eOIpmq9jH2hWE90EYAL7P0kKA7vNInFES/xMjEGOG36CeG8i4tL8naF+WIeREeDXHlDisrZNtLZ4L6BqGGynAj7up5Ol6EU+vp3GONWFV0Fjk0S0J9ThEq/5knXxuUzRbeSeHqCbnyOcso9VsYd/ejr6saFKKl9siu//0SFBOEINqBnZ4u1aa/2QGYRW1VtS4CKSDBZJITwY4JllLbk3kLUbpnFPLhtOcPp1OWsd/a58BFOElWYaFsn2cPxlbrm6CL8/XaKIPnjCaAVM/RPvLVbtusditd8xEfZ7+rUfD8R7offTNy5isQjg== Received: from BN7NAM10FT059.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e8f::52) by BN7NAM10HT207.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e8f::350) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Tue, 26 Jan 2021 19:47:34 +0000 Received: from MWHPR06MB3102.namprd06.prod.outlook.com (2a01:111:e400:7e8f::4c) by BN7NAM10FT059.mail.protection.outlook.com (2a01:111:e400:7e8f::447) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 26 Jan 2021 19:47:34 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:C50DF7FC7D5156852A47F646D08AC34AD41A01BFF5E9260CE68AD371FCC6765C;UpperCasedChecksum:62689F9685B2BE025CBE12DAB0BB25232B78D19F781C387ED800F506D01417AF;SizeAsReceived:7523;Count:47 Received: from MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::d4ee:1260:6f53:3f7b]) by MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::d4ee:1260:6f53:3f7b%6]) with mapi id 15.20.3784.017; Tue, 26 Jan 2021 19:47:34 +0000 From: "Kun Qin" To: devel@edk2.groups.io CC: Jiewen Yao , Jian J Wang , Qi Zhang , Rahul Kumar , Jiewen Yao Subject: [PATCH v4 16/20] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Date: Tue, 26 Jan 2021 11:47:06 -0800 Message-ID: X-Mailer: git-send-email 2.30.0.windows.1 In-Reply-To: <20210126194710.2248-1-kun.q@outlook.com> References: <20210126194710.2248-1-kun.q@outlook.com> X-TMN: [CUZxutBU6eELI6rGp61t7ZFwGuAHTe5I] X-ClientProxiedBy: MWHPR11CA0001.namprd11.prod.outlook.com (2603:10b6:301:1::11) To MWHPR06MB3102.namprd06.prod.outlook.com (2603:10b6:301:3e::35) Return-Path: kun.q@outlook.com X-Microsoft-Original-Message-ID: <20210126194710.2248-14-kun.q@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (50.35.88.161) by MWHPR11CA0001.namprd11.prod.outlook.com (2603:10b6:301:1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.14 via Frontend Transport; Tue, 26 Jan 2021 19:47:31 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 62f8aad6-b159-4f0b-b76f-08d8c2333809 X-MS-TrafficTypeDiagnostic: BN7NAM10HT207: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b6slS/qPDfuCJTnDcSIZYh0ggAq5fP0Yl9Lxzj9xsWGfO1TYPUK1op2B1Kgo4mXdcwIkcbgTio2GL5oZsJFGKPBodorrE0UUSt43iURpLDH9YgH4YeiGCLCFWxqI86eY3I70ydYw7gSeGRmywdWcnX9Zmx0067z+5vm47eh9/bTU8Fcpktm83OJWoyxOGtPL7iWwQkdduIXtrH4x5gf4G7YFVDkLT6gphZIzrtCIrfMBUvSPGEix8+E75MJht7s5 X-MS-Exchange-AntiSpam-MessageData: nlygtRe2vbnvBDPONneEJtWw4/d95/fQDH3A+VRcchnIKYw/N1OMO/XtdKbgZLTSyU6wLdl7CnQnrsAI7cqEqWyfZfXPE1T3gJ8ls63+d7wBlmjXEB+uGGGHZkh55BkYosrQQyeiHXCO+HVwEPKSeg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62f8aad6-b159-4f0b-b76f-08d8c2333809 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 19:47:31.5594 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: BN7NAM10FT059.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7NAM10HT207 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain This change added a new instance of Tpm2DeviceLibDTpm to support drivers of type MM_STANDALONE. It abstracts dynamic Pcd access into separate file for different instances to avoid dynamic usage for StandaloneMm modules. Cc: Jiewen Yao Cc: Jian J Wang Cc: Qi Zhang Cc: Rahul Kumar Signed-off-by: Kun Qin Reviewed-by: Jiewen Yao --- Notes: v4: - Previously reviewed. No change. =20 v3: - Previously reviewed. No change. =20 v2: - Added Reviewed-by tag [Jiewen] - Removed "EFIAPI" for internal functions SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c = | 42 +----------- SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c = | 68 ++++++++++++++++++++ SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c = | 66 +++++++++++++++++++ SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c = | 40 +----------- SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c = | 15 +++-- SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h = | 67 +++++++++++++++++++ SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf = | 3 + SecurityPkg/Library/Tpm2DeviceLibDTpm/{Tpm2DeviceLibDTpm.inf =3D> Tpm2Devi= ceLibDTpmStandaloneMm.inf} | 13 ++-- SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf = | 3 + SecurityPkg/SecurityPkg.dsc = | 1 + 10 files changed, 228 insertions(+), 90 deletions(-) diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c b/Se= curityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c index 42e1ecbce95a..238389dbdb1b 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c @@ -13,29 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include =20 -/** - Return PTP interface type. - - @param[in] Register Pointer to PTP register. - - @return PTP interface type. -**/ -TPM2_PTP_INTERFACE_TYPE -Tpm2GetPtpInterface ( - IN VOID *Register - ); - -/** - Return PTP CRB interface IdleByPass state. - - @param[in] Register Pointer to PTP register. - - @return PTP CRB interface IdleByPass state. -**/ -UINT8 -Tpm2GetIdleByPass ( - IN VOID *Register - ); +#include "Tpm2DeviceLibDTpm.h" =20 /** This service enables the sending of commands to the TPM2. @@ -145,21 +123,5 @@ Tpm2DeviceLibConstructor ( VOID ) { - TPM2_PTP_INTERFACE_TYPE PtpInterface; - UINT8 IdleByPass; - - // - // Cache current active TpmInterfaceType only when needed - // - if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D 0xFF) { - PtpInterface =3D Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTp= mBaseAddress)); - PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface); - } - - if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D Tpm2PtpInterfaceCrb && Pcd= Get8(PcdCRBIdleByPass) =3D=3D 0xFF) { - IdleByPass =3D Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBase= Address)); - PcdSet8S(PcdCRBIdleByPass, IdleByPass); - } - - return EFI_SUCCESS; + return InternalTpm2DeviceLibDTpmCommonConstructor (); } diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c = b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c new file mode 100644 index 000000000000..bc35e257e105 --- /dev/null +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c @@ -0,0 +1,68 @@ +/** @file + This file abstract internal interfaces of which implementation differs p= er library instance. + +Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include "Tpm2DeviceLibDTpm.h" + +/** + Return cached PTP CRB interface IdleByPass state. + + @return Cached PTP CRB interface IdleByPass state. +**/ +UINT8 +GetCachedIdleByPass ( + VOID + ) +{ + return PcdGet8(PcdCRBIdleByPass); +} + +/** + Return cached PTP interface type. + + @return Cached PTP interface type. +**/ +TPM2_PTP_INTERFACE_TYPE +GetCachedPtpInterface ( + VOID + ) +{ + return PcdGet8(PcdActiveTpmInterfaceType); +} + +/** + The common function cache current active TpmInterfaceType when needed. + + @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not= support register DTPM2.0 instance +**/ +EFI_STATUS +InternalTpm2DeviceLibDTpmCommonConstructor ( + VOID + ) +{ + TPM2_PTP_INTERFACE_TYPE PtpInterface; + UINT8 IdleByPass; + + // + // Cache current active TpmInterfaceType only when needed + // + if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D 0xFF) { + PtpInterface =3D Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTp= mBaseAddress)); + PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface); + } + + if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D Tpm2PtpInterfaceCrb && Pcd= Get8(PcdCRBIdleByPass) =3D=3D 0xFF) { + IdleByPass =3D Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBase= Address)); + PcdSet8S(PcdCRBIdleByPass, IdleByPass); + } + + return EFI_SUCCESS; +} diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandal= oneMm.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalone= Mm.c new file mode 100644 index 000000000000..eac866d2a77a --- /dev/null +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c @@ -0,0 +1,66 @@ +/** @file + This file abstract internal interfaces of which implementation differs p= er library instance. + +Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include "Tpm2DeviceLibDTpm.h" + +TPM2_PTP_INTERFACE_TYPE mActiveTpmInterfaceType; +UINT8 mCRBIdleByPass; + +/** + Return cached PTP CRB interface IdleByPass state. + + @return Cached PTP CRB interface IdleByPass state. +**/ +UINT8 +GetCachedIdleByPass ( + VOID + ) +{ + return mCRBIdleByPass; +} + +/** + Return cached PTP interface type. + + @return Cached PTP interface type. +**/ +TPM2_PTP_INTERFACE_TYPE +GetCachedPtpInterface ( + VOID + ) +{ + return mActiveTpmInterfaceType; +} + +/** + The common function cache current active TpmInterfaceType when needed. + + @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not= support register DTPM2.0 instance +**/ +EFI_STATUS +InternalTpm2DeviceLibDTpmCommonConstructor ( + VOID + ) +{ + mActiveTpmInterfaceType =3D 0xFF; + mCRBIdleByPass =3D 0xFF; + + // + // Always cache current active TpmInterfaceType for StandaloneMm impleme= ntation + // + mActiveTpmInterfaceType =3D Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet= 64 (PcdTpmBaseAddress)); + + if (mActiveTpmInterfaceType =3D=3D Tpm2PtpInterfaceCrb) { + mCRBIdleByPass =3D Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpm= BaseAddress)); + } + + return EFI_SUCCESS; +} diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c b/= SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c index 691eaa40c045..053e597d2ee2 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c @@ -16,29 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 -/** - Return PTP interface type. - - @param[in] Register Pointer to PTP register. - - @return PTP interface type. -**/ -TPM2_PTP_INTERFACE_TYPE -Tpm2GetPtpInterface ( - IN VOID *Register - ); - -/** - Return PTP CRB interface IdleByPass state. - - @param[in] Register Pointer to PTP register. - - @return PTP CRB interface IdleByPass state. -**/ -UINT8 -Tpm2GetIdleByPass ( - IN VOID *Register - ); +#include "Tpm2DeviceLibDTpm.h" =20 /** Dump PTP register information. @@ -102,8 +80,6 @@ Tpm2InstanceLibDTpmConstructor ( ) { EFI_STATUS Status; - TPM2_PTP_INTERFACE_TYPE PtpInterface; - UINT8 IdleByPass; =20 Status =3D Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device); if ((Status =3D=3D EFI_SUCCESS) || (Status =3D=3D EFI_UNSUPPORTED)) { @@ -111,19 +87,7 @@ Tpm2InstanceLibDTpmConstructor ( // Unsupported means platform policy does not need this instance enabl= ed. // if (Status =3D=3D EFI_SUCCESS) { - // - // Cache current active TpmInterfaceType only when needed - // - if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D 0xFF) { - PtpInterface =3D Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (P= cdTpmBaseAddress)); - PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface); - } - - if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D Tpm2PtpInterfaceCrb &&= PcdGet8(PcdCRBIdleByPass) =3D=3D 0xFF) { - IdleByPass =3D Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpm= BaseAddress)); - PcdSet8S(PcdCRBIdleByPass, IdleByPass); - } - + Status =3D InternalTpm2DeviceLibDTpmCommonConstructor (); DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress)); } return EFI_SUCCESS; diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c b/SecurityPkg/= Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c index 2c73385b6ce5..f1f80916834f 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c @@ -2,6 +2,7 @@ PTP (Platform TPM Profile) CRB (Command Response Buffer) interface used = by dTPM2.0 library. =20 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+Copyright (c), Microsoft Corporation. SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -19,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include =20 +#include "Tpm2DeviceLibDTpm.h" + // // Execution of the command may take from several seconds to minutes for c= ertain // commands, such as key generation. @@ -174,7 +177,7 @@ PtpCrbTpmCommand ( // STEP 0: // if CapCRbIdelByPass =3D=3D 0, enforce Idle state before sending comma= nd // - if (PcdGet8(PcdCRBIdleByPass) =3D=3D 0 && (MmioRead32((UINTN)&CrbReg->Cr= bControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) =3D=3D 0){ + if (GetCachedIdleByPass () =3D=3D 0 && (MmioRead32((UINTN)&CrbReg->CrbCo= ntrolStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) =3D=3D 0){ Status =3D PtpCrbWaitRegisterBits ( &CrbReg->CrbControlStatus, PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE, @@ -330,7 +333,7 @@ PtpCrbTpmCommand ( // Goto Ready State if command is completed successfully and TPM support= IdleBypass // If not supported. flow down to GoIdle // - if (PcdGet8(PcdCRBIdleByPass) =3D=3D 1) { + if (GetCachedIdleByPass () =3D=3D 1) { MmioWrite32((UINTN)&CrbReg->CrbControlRequest, PTP_CRB_CONTROL_AREA_RE= QUEST_COMMAND_READY); return Status; } @@ -350,7 +353,7 @@ PtpCrbTpmCommand ( // Only enforce Idle state transition if execution fails when CRBIdleByp= ass=3D=3D1 // Leave regular Idle delay at the beginning of next command execution // - if (PcdGet8(PcdCRBIdleByPass) =3D=3D 1){ + if (GetCachedIdleByPass () =3D=3D 1){ Status =3D PtpCrbWaitRegisterBits ( &CrbReg->CrbControlStatus, PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE, @@ -519,7 +522,7 @@ DumpPtpInfo ( Vid =3D 0xFFFF; Did =3D 0xFFFF; Rid =3D 0xFF; - PtpInterface =3D PcdGet8(PcdActiveTpmInterfaceType); + PtpInterface =3D GetCachedPtpInterface (); DEBUG ((EFI_D_INFO, "PtpInterface - %x\n", PtpInterface)); switch (PtpInterface) { case Tpm2PtpInterfaceCrb: @@ -564,7 +567,7 @@ DTpm2SubmitCommand ( { TPM2_PTP_INTERFACE_TYPE PtpInterface; =20 - PtpInterface =3D PcdGet8(PcdActiveTpmInterfaceType); + PtpInterface =3D GetCachedPtpInterface (); switch (PtpInterface) { case Tpm2PtpInterfaceCrb: return PtpCrbTpmCommand ( @@ -603,7 +606,7 @@ DTpm2RequestUseTpm ( { TPM2_PTP_INTERFACE_TYPE PtpInterface; =20 - PtpInterface =3D PcdGet8(PcdActiveTpmInterfaceType); + PtpInterface =3D GetCachedPtpInterface (); switch (PtpInterface) { case Tpm2PtpInterfaceCrb: return PtpCrbRequestUseTpm ((PTP_CRB_REGISTERS_PTR) (UINTN) PcdGet64 (= PcdTpmBaseAddress)); diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h b/Se= curityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h new file mode 100644 index 000000000000..9fff98952251 --- /dev/null +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h @@ -0,0 +1,67 @@ +/** @file + This header file includes common internal fuction prototypes. + +Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _TPM2_DEVICE_LIB_DTPM_H_ +#define _TPM2_DEVICE_LIB_DTPM_H_ + +/** + Return PTP interface type. + + @param[in] Register Pointer to PTP register. + + @return PTP interface type. +**/ +TPM2_PTP_INTERFACE_TYPE +Tpm2GetPtpInterface ( + IN VOID *Register + ); + +/** + Return PTP CRB interface IdleByPass state. + + @param[in] Register Pointer to PTP register. + + @return PTP CRB interface IdleByPass state. +**/ +UINT8 +Tpm2GetIdleByPass ( + IN VOID *Register + ); + +/** + Return cached PTP interface type. + + @return Cached PTP interface type. +**/ +TPM2_PTP_INTERFACE_TYPE +GetCachedPtpInterface ( + VOID + ); + +/** + Return cached PTP CRB interface IdleByPass state. + + @return Cached PTP CRB interface IdleByPass state. +**/ +UINT8 +GetCachedIdleByPass ( + VOID + ); + +/** + The common function cache current active TpmInterfaceType when needed. + + @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not= support register DTPM2.0 instance +**/ +EFI_STATUS +InternalTpm2DeviceLibDTpmCommonConstructor ( + VOID + ); + +#endif // _TPM2_DEVICE_LIB_DTPM_H_ diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf b/= SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf index 2b627504634d..be3a0053ccce 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf @@ -11,6 +11,7 @@ # only uses TPM 2.0 DTPM device. # # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -34,6 +35,8 @@ [Sources] Tpm2Tis.c Tpm2Ptp.c Tpm2DeviceLibDTpm.c + Tpm2DeviceLibDTpmBase.c + Tpm2DeviceLibDTpm.h =20 [Packages] MdePkg/MdePkg.dec diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf b/= SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf similarity index 70% copy from SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf copy to SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm= .inf index 2b627504634d..18c08ad8bdcc 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.i= nf @@ -11,19 +11,20 @@ # only uses TPM 2.0 DTPM device. # # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: BSD-2-Clause-Patent # ## =20 [Defines] INF_VERSION =3D 0x00010005 - BASE_NAME =3D Tpm2DeviceLibDTpm - MODULE_UNI_FILE =3D Tpm2DeviceLibDTpm.uni - FILE_GUID =3D E54A3327-A345-4068-8842-70AC0D519855 + BASE_NAME =3D Tpm2DeviceLibDTpmStandaloneMm + FILE_GUID =3D 9A5DB21A-FF0B-46D0-8672-B4F83FEF1F0E MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D Tpm2DeviceLib|PEIM DXE_DRIVER DXE_RUN= TIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER + LIBRARY_CLASS =3D Tpm2DeviceLib|MM_STANDALONE CONSTRUCTOR =3D Tpm2DeviceLibConstructor + # # The following information is for reference only and not required by the = build tools. # @@ -34,6 +35,8 @@ [Sources] Tpm2Tis.c Tpm2Ptp.c Tpm2DeviceLibDTpm.c + Tpm2DeviceLibDTpmStandaloneMm.c + Tpm2DeviceLibDTpm.h =20 [Packages] MdePkg/MdePkg.dec @@ -49,5 +52,3 @@ [LibraryClasses] =20 [Pcd] gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES - gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType ## PRODUCES - gEfiSecurityPkgTokenSpaceGuid.PcdCRBIdleByPass ## PRODUCES diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf = b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf index 5f267f552ce3..31113d93ee41 100644 --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf @@ -6,6 +6,7 @@ # and PTP (Platform TPM Profile) functions. # # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -30,6 +31,8 @@ [Sources] Tpm2Tis.c Tpm2Ptp.c Tpm2InstanceLibDTpm.c + Tpm2DeviceLibDTpmBase.c + Tpm2DeviceLibDTpm.h =20 [Packages] MdePkg/MdePkg.dec diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 7240b2573e4e..618420a56c33 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -211,6 +211,7 @@ [Components] SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf =20 --=20 2.30.0.windows.1