From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web09.39647.1609114119514377033 for ; Sun, 27 Dec 2020 16:08:39 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=OSVgum/o; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: jiewen.yao@intel.com) IronPort-SDR: +MnT9A4pvlCD5fVeR6NafOu/Fv5tSoNC/Tl5TLyVn9apcN7ci+fXe1U9JCCncRZAxNZ0jIJRwd ggC01xCWcOXQ== X-IronPort-AV: E=McAfee;i="6000,8403,9847"; a="155536939" X-IronPort-AV: E=Sophos;i="5.78,453,1599548400"; d="scan'208";a="155536939" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Dec 2020 16:08:37 -0800 IronPort-SDR: Px0K3qaEQseFbn8+DIfvm7LeduJ1cIFJJZHBXrHG/siblognKWcSMtttfZCtgadUX3hD4BfFNE Q02lOMpwza+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,453,1599548400"; d="scan'208";a="375402988" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga008.jf.intel.com with ESMTP; 27 Dec 2020 16:08:36 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sun, 27 Dec 2020 16:08:33 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Sun, 27 Dec 2020 16:08:33 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.107) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Sun, 27 Dec 2020 16:08:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gAlukcHlT2vuY+SwL6dfLztZntKt3crX9dZAjKs/JUaZqOMAMii/GLEwf1rR8U0FjVCdfMZMTtDzaVbxm9WCYvqZuvZtFnDXAlgX55mHlG0EMfUO6O0tywZvBgL+pDgp0+a4Wd3WMQyyfB/9cROJfGIbpIUvMip1l9/J58EW7um4ZIVKjyZiYN/4DYhtXJ49xV7zDpAEwiC9Pujhjsd/IyAzAj7ipjdJN59GH/8VwzM88x+WghNFsmyKxS1SbkR10fuLDd3yZkEt9vB+kvo74gIx7IRrKR1bt/zjQipwEDwnKMxlv1YC2WkQWHwTX4RKO5qFxmMEieB5gt3W9omJ/w== 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=vpgs7/5BugjPpIssMQf0JbvpkV+P1qXC3lpz31q/g0M=; b=XbocXp7ZbPg1UxNxjmnx2sbmtTBVvl/PBqHdafqLkBaVzEh7kUpzst16iCcpgZQkE1pSyF/dTsAWYuI6bPjTaFZbjW5R+UtwfQmk1YMvUUMhMXgAILzt+kDdMJFZSawzDjF0NgG3Bknq2tuDQtH3z5NdyuM+6bAtK4Xf5v4U9yFhFDKHZL62L0gvn8D8cypf9YhUlaMBlLuaUsmt6an8YIGrRt/A/Al6Jf3Up3xKPMLo2VV4QXELXEpgwReNM+P4r6xuzF1Uw7NBJa4zR1LjvtK9fatsRkurgSxXHJ7vsBdC5PsR25nCWCt3vf/uq0c92js594dcS1A4d6rtS2e/wg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vpgs7/5BugjPpIssMQf0JbvpkV+P1qXC3lpz31q/g0M=; b=OSVgum/o6Su/4wpqRW8LTnivVg5zBHGqNbvFCVTH0w76kgBq7gGKQ000tLGwSwevSmWcnQjaMKjAMUIpFAXa3ZapsRj+AMDn2M3q/UtwwqdyN0FN8FZMNMR4f2ViGq0DguZC7Ua7Sz11vVSk/bqt2XxBL7vef6owvi/GNE7wVXM= Received: from CY4PR11MB1288.namprd11.prod.outlook.com (2603:10b6:903:23::8) by CY4PR11MB0054.namprd11.prod.outlook.com (2603:10b6:910:79::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.31; Mon, 28 Dec 2020 00:08:26 +0000 Received: from CY4PR11MB1288.namprd11.prod.outlook.com ([fe80::e058:fd5a:28d8:2b17]) by CY4PR11MB1288.namprd11.prod.outlook.com ([fe80::e058:fd5a:28d8:2b17%12]) with mapi id 15.20.3700.031; Mon, 28 Dec 2020 00:08:26 +0000 From: "Yao, Jiewen" To: Kun Qin , "devel@edk2.groups.io" CC: "Wang, Jian J" , "Zhang, Qi1" , "Kumar, Rahul1" Subject: Re: [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Thread-Topic: [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Thread-Index: AQHW1W64kSjUsFkDjEm9k3bUPEgwmKoLr/oQ Date: Mon, 28 Dec 2020 00:08:26 +0000 Message-ID: References: <20201218185011.1366-1-kun.q@outlook.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: outlook.com; dkim=none (message not signed) header.d=none;outlook.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.102.204.37] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d97801d8-851c-43ce-d5a6-08d8aac4b319 x-ms-traffictypediagnostic: CY4PR11MB0054: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: iwLnhXfQ1BSHPfGDBd1j8RM9Bz+ux5SndgP9rMclYZHNleZAsVe741trkfq05b8HXz5pZPKUJ5j9lxi78qAiD3JJYN68IDD9aSykGCKMhNdQOEoV4mbPNMdFDklxauYckaeerjF11/3XGS3AkOS65tw/vwHk2VXUXDBlMpQI6rVwmmD5qXOKkXNuRM0eLkDvLUrK60ykdrNSjx+Q+PVD3a2Yr1O8r07sBfGb3b5yyiRMOn2S2cfm9VW/IfpI8isCNlhgINNx9K9jIRF9nlQXpsKrn+kwhq+zP7cVip/Bo1LDXam9RunyML1EKBlKlvBRSArAysGyycINJPDR/+h/yQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR11MB1288.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(346002)(376002)(136003)(366004)(396003)(15650500001)(66476007)(4326008)(66446008)(26005)(54906003)(110136005)(5660300002)(2906002)(83380400001)(45080400002)(64756008)(52536014)(76116006)(86362001)(66946007)(8676002)(6506007)(107886003)(19627235002)(8936002)(9686003)(316002)(7696005)(53546011)(71200400001)(55016002)(66556008)(30864003)(33656002)(478600001)(186003)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?8zvES9AyMWvjPf2IRlaA2X5h/lwyH/Hy3pMUS2mKy6wS4j7T01UEtC67QL6+?= =?us-ascii?Q?TlmJOObP381bggBUNMxmzQryMOk7x919bn05MczkHQQbVN9cgqb6UDhpoERz?= =?us-ascii?Q?qJ9WLfruvxhx/WehiSOvqoUqsgI+cCeedgE+67zlHXxElU/fbDckvhgdNNgW?= =?us-ascii?Q?1R9yjRIfxqpRZ/pQ0J7rGsLsO2nAbmduNVwenX48eejHpa4vzcAUdQL6Jxf5?= =?us-ascii?Q?WTuq0JVT6Af26PoVdY8gsarCQiGZKSfqzsEzCYWh+x9sbvufYg9STAP6HZtg?= =?us-ascii?Q?cR/coQxSJc3XW4jOvcbpE18QNlN27Gh7cmpofRDE6Ejn4lCD1NmYBoIV6Pel?= =?us-ascii?Q?Vzad8EoIgUJ2RYCA77vxKKflr3FBCi5qjUkZ8XFeSkDIRT2mHGVOBWNYYM/4?= =?us-ascii?Q?wXwnK5bO1CkGyhjsIobq5LE3uFtx28+jQXKDzHPnz06KomxC6LmO7cSzAyBV?= =?us-ascii?Q?ifALp3DZK+qSQXf+0fBbfGRHao4g9y4ZbwKZYM+im69UKa3cZeIdUR+ZYCEy?= =?us-ascii?Q?HWY1GDKG8cP6EO4i3uD/rsnwEPAGfe9NaCl8MCk4gUbH4pw7kkwUtRUzPTeX?= =?us-ascii?Q?pJJYZC1aYUtph62+cyfHM8wC+K+zMPI5UZJzweFgXM9yV3N0B3ZGwWlFb7Ln?= =?us-ascii?Q?MTpKc4oYQs+/ZMekSnrVoLZYpH3fTRkxV26qPQy8HapW1mdFzVU1GcKbDSjU?= =?us-ascii?Q?fbDMF4LwVC0uvZogaulZzmdO8G8FBk4eQ8RNGcbjgyHVHFBQ+4BrxQq6wbie?= =?us-ascii?Q?63ktCcL2IpLxUXZrt5qh+3g+DnAE4F9hpvJ9xtXh6L8fQYGtZFLlIvLANchf?= =?us-ascii?Q?YyKe22AlW/ImS17FIGuiFFzYrnM/iVNABWxv8dFP/slbK5zDMhUdAiX+vKw7?= =?us-ascii?Q?MjafbihQm9KrMB5uQMRsCDd9pFZnTtAcd6prhSzjAYcQqTiU66aj4xmAeOQ1?= =?us-ascii?Q?yZgdzOcj+vRFKpIqm4Erj5ad/DcoEbVX2GhKS9EEI+4=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY4PR11MB1288.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d97801d8-851c-43ce-d5a6-08d8aac4b319 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Dec 2020 00:08:26.6892 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: QtChAOvPZzCELgGubbPqkGUHjIiplFeWSVaCsE8Bmi8wNvZhfJa9JuzimVYXfQXl4T+dgLb3rqRBHDpifqT6+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR11MB0054 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jiewen Yao > -----Original Message----- > From: Kun Qin > Sent: Saturday, December 19, 2020 2:50 AM > To: devel@edk2.groups.io > Cc: Yao, Jiewen ; Wang, Jian J > ; Zhang, Qi1 ; Kumar, > Rahul1 > Subject: [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce > StandaloneMm instance >=20 > 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. >=20 > Cc: Jiewen Yao > Cc: Jian J Wang > Cc: Qi Zhang > Cc: Rahul Kumar >=20 > Signed-off-by: Kun Qin > --- > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c > | 42 +----------- > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c > | 69 ++++++++++++++++++++ >=20 > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalone > Mm.c | 67 +++++++++++++++++++ > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c > | 40 +----------- > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c > | 15 +++-- > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h > | 68 +++++++++++++++++++ > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf > | 3 + > SecurityPkg/Library/Tpm2DeviceLibDTpm/{Tpm2DeviceLibDTpm.inf =3D> > Tpm2DeviceLibDTpmStandaloneMm.inf} | 13 ++-- > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf > | 3 + > SecurityPkg/SecurityPkg.dsc = | 1 + > 10 files changed, 231 insertions(+), 90 deletions(-) >=20 > diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c > b/SecurityPkg/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 > (PcdTpmBaseAddress)); > - PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface); > - } > - > - if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D Tpm2PtpInterfaceCrb && > PcdGet8(PcdCRBIdleByPass) =3D=3D 0xFF) { > - IdleByPass =3D Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 > (PcdTpmBaseAddress)); > - 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..aaa215eee9f7 > --- /dev/null > +++ > b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c > @@ -0,0 +1,69 @@ > +/** @file > + This file abstract internal interfaces of which implementation differs= per > 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 > +EFIAPI > +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 > (PcdTpmBaseAddress)); > + PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface); > + } > + > + if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D Tpm2PtpInterfaceCrb && > PcdGet8(PcdCRBIdleByPass) =3D=3D 0xFF) { > + IdleByPass =3D Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 > (PcdTpmBaseAddress)); > + PcdSet8S(PcdCRBIdleByPass, IdleByPass); > + } > + > + return EFI_SUCCESS; > +} > diff --git > a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon > eMm.c > b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon > eMm.c > new file mode 100644 > index 000000000000..9e3d3f0a8e9d > --- /dev/null > +++ > b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon > eMm.c > @@ -0,0 +1,67 @@ > +/** @file > + This file abstract internal interfaces of which implementation differs= per > 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 > +EFIAPI > +InternalTpm2DeviceLibDTpmCommonConstructor ( > + VOID > + ) > +{ > + mActiveTpmInterfaceType =3D 0xFF; > + mCRBIdleByPass =3D 0xFF; > + > + // > + // Always cache current active TpmInterfaceType for StandaloneMm > implementation > + // > + mActiveTpmInterfaceType =3D Tpm2GetPtpInterface ((VOID *) (UINTN) > PcdGet64 (PcdTpmBaseAddress)); > + > + if (mActiveTpmInterfaceType =3D=3D Tpm2PtpInterfaceCrb) { > + mCRBIdleByPass =3D Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 > (PcdTpmBaseAddress)); > + } > + > + 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 > enabled. > // > 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 > (PcdTpmBaseAddress)); > - PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface); > - } > - > - if (PcdGet8(PcdActiveTpmInterfaceType) =3D=3D Tpm2PtpInterfaceCrb = && > PcdGet8(PcdCRBIdleByPass) =3D=3D 0xFF) { > - IdleByPass =3D Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 > (PcdTpmBaseAddress)); > - 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 certain > // commands, such as key generation. > @@ -174,7 +177,7 @@ PtpCrbTpmCommand ( > // STEP 0: > // if CapCRbIdelByPass =3D=3D 0, enforce Idle state before sending com= mand > // > - if (PcdGet8(PcdCRBIdleByPass) =3D=3D 0 && (MmioRead32((UINTN)&CrbReg- > >CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) =3D=3D 0){ > + if (GetCachedIdleByPass () =3D=3D 0 && (MmioRead32((UINTN)&CrbReg- > >CrbControlStatus) & 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_REQUEST_COMMAND_READY); > return Status; > } > @@ -350,7 +353,7 @@ PtpCrbTpmCommand ( > // Only enforce Idle state transition if execution fails when > CRBIdleBypass=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/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h > new file mode 100644 > index 000000000000..4eabb6cd182e > --- /dev/null > +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h > @@ -0,0 +1,68 @@ > +/** @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 > +EFIAPI > +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/Tpm2DeviceLibDTpmStandalon > eMm.inf > similarity index 70% > copy from > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf > copy to > SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalone > Mm.inf > index 2b627504634d..18c08ad8bdcc 100644 > --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf > +++ > b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon > eMm.inf > @@ -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-70AC0D51985= 5 > + BASE_NAME =3D Tpm2DeviceLibDTpmStandaloneMm > + FILE_GUID =3D 9A5DB21A-FF0B-46D0-8672-B4F83FEF1F0= E > MODULE_TYPE =3D BASE > VERSION_STRING =3D 1.0 > - LIBRARY_CLASS =3D Tpm2DeviceLib|PEIM DXE_DRIVER > DXE_RUNTIME_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 th= e > 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/Tpm2DeviceLibDTpmStandalone > Mm.inf > SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf > SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf >=20 > -- > 2.28.0.windows.1