Skip to contentSkip to conversation

RFC: ovmf: Add support for TPM Physical Presence interface

PATCH Superseded [email protected] 3 participants 9 messages May 18, 2018 – May 22, 2018

v3 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v3 cover RFC: ovmf: Add support for TPM Physical Presence interface

From: Marc-André Lureau <[email protected]>

Hi,

The following series adds basic TPM PPI 1.3 support for OVMF-on-QEMU with TPM2 (I haven't looked at TPM1, for lack of interest).

PPI test runs successfully with Windows 10 WHLK, despite the limited number of supported funcions (tpm2_ppi_funcs table, in particular, no function allows to manipulate Tcg2PhysicalPresenceFlags)

The way it works is relatively simple: a memory region is allocated by QEMU to save PPI related variables. An ACPI interface is exposed by QEMU to let the guest manipulate those. At boot, ovmf processes and updates the PPI qemu region and request variables.

I build edk2 with:

$ build -DTPM2_ENABLE

I test with qemu & swtpm/libtpms (tpm2 branches, swtpm_setup.sh --tpm2
--tpm-state tpmstatedir)

$ swtpm socket --tpmstate tpmstatedir --ctrl type=unixio,path=tpmsock
  --tpm2 &
$ qemu .. -chardev socket,id=chrtpm,path=tpmsock -tpmdev
  emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0

Github trees:
https://github.com/elmarco/edk2/tree/tpm-ppi
https://github.com/elmarco/qemu/tree/tpm-ppi

Thanks

v3: after Laszlo review
- dropped DxeTcg2PhysicalPresenceLib.uni
- removed mTpm2PPIFuncs static initialization, use hard-coded assignments
- declared STATIC the functions that should be
- fixed an OUT/IN decorator
- use EFI_PROTOCOL_ERROR instead of EFI_INVALID_PARAMETER when PPI initialization fails
- replaced EFI_D_INFO with DEBUG_INFO
- added a check for mPpi address that it doesn't cross a page boundary
- added a GetMemorySpaceDescriptor() check for memory type
- declared *mPpi as volatile, to correct mmio access
- a few more style changes
- comments updated
- some minor dead code/inclusion/defines removal
- added a few r-b tags

v2:
- style and commit message fixes

Marc-André Lureau (4):
OvmfPkg: add Tcg2PhysicalPresenceLibNull when !TPM2_ENABLE OvmfPkg/IndustryStandard: add QemuTpm.h header
OvmfPkg: add Tcg2PhysicalPresenceLibQemu OvmfPkg/PlatformBootManagerLib: process TPM PPI request

 OvmfPkg/OvmfPkgIa32.dsc                       |   4 +-
 OvmfPkg/OvmfPkgIa32X64.dsc                    |   4 +-
 OvmfPkg/OvmfPkgX64.dsc                        |   4 +-
 .../PlatformBootManagerLib.inf                |   2 +
 .../DxeTcg2PhysicalPresenceLib.inf            |  33 +
 .../DxeTcg2PhysicalPresenceLib.inf            |  46 +-
 OvmfPkg/Include/IndustryStandard/QemuTpm.h    |  69 ++
 .../PlatformBootManagerLib/BdsPlatform.c      |   6 +
 .../DxeTcg2PhysicalPresenceLib.c              |  20 +-
 .../DxeTcg2PhysicalPresenceLib.c              | 919 ++++++++++++++++++
 .../PhysicalPresenceStrings.uni               |  33 +-
 11 files changed, 1081 insertions(+), 59 deletions(-)
 create mode 100644 OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
 copy {SecurityPkg/Library/DxeTcg2PhysicalPresenceLib => OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu}/DxeTcg2PhysicalPresenceLib.inf (66%)
 create mode 100644 OvmfPkg/Include/IndustryStandard/QemuTpm.h
 copy EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ia32/CpuSleep.c => OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.c (55%)
 create mode 100644 OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c
 copy {SecurityPkg/Library/DxeTcg2PhysicalPresenceLib => OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu}/PhysicalPresenceStrings.uni (56%)
Signature · 1 line
2.17.0.253.g3dd125b46d
#1 lore raw

PATCH v3 1/4 OvmfPkg: add Tcg2PhysicalPresenceLibNull when !TPM2_ENABLE

From: Marc-André Lureau <[email protected]>

This NULL library will let us call Tcg2PhysicalPresenceLibProcessRequest() unconditionally from BdsPlatform when building without TPM2_ENABLE.

Contributed-under: TianoCore Contribution Agreement 1.1

---
 OvmfPkg/OvmfPkgIa32.dsc                                                                                                                                         |  2 ++
 OvmfPkg/OvmfPkgIa32X64.dsc                                                                                                                                      |  2 ++
 OvmfPkg/OvmfPkgX64.dsc                                                                                                                                          |  2 ++
 OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf                                                                                      | 33 ++++++++++++++++++++
 EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ia32/CpuSleep.c => OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.c | 20 ++++++------
 5 files changed, 49 insertions(+), 10 deletions(-)
OvmfPkg/OvmfPkgIa32.dsc +2 -0
index 2d6c4c4615b6..6c361b73cd55 100644
@@ -208,6 +208,8 @@ [LibraryClasses]
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
   Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf
   Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
+!else
+  Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
 !endif
 
 [LibraryClasses.common]
OvmfPkg/OvmfPkgIa32X64.dsc +2 -0
index 43158c5f0627..62a6075a671d 100644
@@ -213,6 +213,8 @@ [LibraryClasses]
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
   Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf
   Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
+!else
+  Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
 !endif
 
 [LibraryClasses.common]
OvmfPkg/OvmfPkgX64.dsc +2 -0
index d1fdf7c307c2..cbab1aa328c6 100644
@@ -213,6 +213,8 @@ [LibraryClasses]
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
   Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf
   Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
+!else
+  Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
 !endif
 
 [LibraryClasses.common]
OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf new file +33 -0
new file mode 100644
index 000000000000..92ce5f04b37f
@@ -0,0 +1,33 @@
+## @file
+#  NULL Tcg2PhysicalPresenceLib library instance
+#
+# Under SecurityPkg, the corresponding library instance will check and
+# execute TPM 2.0 request from OS or BIOS; the request may ask for user
+# confirmation before execution. This Null instance implements a no-op
+# Tcg2PhysicalPresenceLibProcessRequest(), without user interaction.
+#
+# Copyright (C) 2018, Red Hat, Inc.
+# Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DxeTcg2PhysicalPresenceLibNull
+  FILE_GUID                      = 2A6BA243-DC22-42D8-9C3D-AE3728DC7AFA
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = Tcg2PhysicalPresenceLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_APPLICATION UEFI_DRIVER
+
+[Sources]
+  DxeTcg2PhysicalPresenceLib.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  SecurityPkg/SecurityPkg.dec
OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.c renamed from EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ia32/CpuSleep.c +10 -10
similarity index 55%
copy from EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ia32/CpuSleep.c
copy to OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.c
index 3d94bd6d6fb6..fa45e36999c0 100644
@@ -1,7 +1,8 @@
-/**
-  CpuSleep function.
+/** @file
+  NULL Tcg2PhysicalPresenceLib library instance
 
-  Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2018, Red Hat, Inc.
+  Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -12,16 +13,15 @@
 
 **/
 
-#include "BaseLibInternals.h"
+#include <Library/Tcg2PhysicalPresenceLib.h>
 
 VOID
 EFIAPI
-CpuSleep (
-  VOID
+Tcg2PhysicalPresenceLibProcessRequest (
+  IN      TPM2B_AUTH                     *PlatformAuth  OPTIONAL
   )
 {
-  _asm {
-    hlt
-  }
+  //
+  // do nothing
+  //
 }
-
Signature · 1 line
2.17.0.253.g3dd125b46d
Reviewed-by on v3 1/4
#2 lore raw

Re: [Qemu-devel] [edk2] [PATCH v3 1/4] OvmfPkg: add Tcg2PhysicalPresenceLibNull when !TPM2_ENABLE

Quoted 29 lines · On 05/18/18 14:23, [email protected] wrote:
OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf new file +23 -0
new file mode 100644
index 000000000000..92ce5f04b37f
@@ -0,0 +1,33 @@
+## @file
+#  NULL Tcg2PhysicalPresenceLib library instance
+#
+# Under SecurityPkg, the corresponding library instance will check and
+# execute TPM 2.0 request from OS or BIOS; the request may ask for user
+# confirmation before execution. This Null instance implements a no-op
+# Tcg2PhysicalPresenceLibProcessRequest(), without user interaction.
+#
+# Copyright (C) 2018, Red Hat, Inc.
+# Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DxeTcg2PhysicalPresenceLibNull
+  FILE_GUID                      = 2A6BA243-DC22-42D8-9C3D-AE3728DC7AFA

OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf line 33

Quoted 10 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf new file +10 -0
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = Tcg2PhysicalPresenceLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_APPLICATION UEFI_DRIVER
+
+[Sources]
+  DxeTcg2PhysicalPresenceLib.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  SecurityPkg/SecurityPkg.dec

Here my suggestion was to drop MdeModulePkg.dec, and keep MdePkg.dec and SecurityPkg.dec.

Anyway, I plan to fix that up for you.

With it fixed:

Thanks
Laszlo

#3 lore raw

PATCH v3 2/4 OvmfPkg/IndustryStandard: add QemuTpm.h header

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Add some common macros and type definitions corresponding to the QEMU TPM interface.

Contributed-under: TianoCore Contribution Agreement 1.1

---
 OvmfPkg/Include/IndustryStandard/QemuTpm.h | 69 ++++++++++++++++++++
 1 file changed, 69 insertions(+)
OvmfPkg/Include/IndustryStandard/QemuTpm.h new file +69 -0
new file mode 100644
index 000000000000..a342cbc347f1
@@ -0,0 +1,69 @@
+/** @file
+  Macro and type definitions corresponding to the QEMU TPM interface.
+
+  Refer to "docs/specs/tpm.txt" in the QEMU source directory.
+
+  Copyright (C) 2018, Red Hat, Inc.
+  Copyright (c) 2018, IBM Corporation. All rights reserved.<BR>
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#ifndef __QEMU_TPM_H__
+#define __QEMU_TPM_H__
+
+#include <Base.h>
+
+//
+// whether function is blocked by BIOS settings; bits 0, 1, 2
+//
+#define QEMU_TPM_PPI_FUNC_NOT_IMPLEMENTED     (0 << 0)
+#define QEMU_TPM_PPI_FUNC_BIOS_ONLY           (1 << 0)
+#define QEMU_TPM_PPI_FUNC_BLOCKED             (2 << 0)
+#define QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ     (3 << 0)
+#define QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ (4 << 0)
+#define QEMU_TPM_PPI_FUNC_MASK                (7 << 0)
+
+//
+// The following structure is shared between firmware and ACPI.
+//
+#pragma pack (1)
+typedef struct {
+  UINT8  Func[256];           // func
+  UINT8  In;                  // ppin
+  UINT32 Ip;                  // ppip
+  UINT32 Response;            // pprp
+  UINT32 Request;             // pprq
+  UINT32 RequestParameter;    // pprm
+  UINT32 LastRequest;         // lppr
+  UINT32 FRet;                // fret
+  UINT8  Res1[0x40];          // res1
+  UINT8  NextStep;            // next_step
+} QEMU_TPM_PPI;
+#pragma pack ()
+
+//
+// The following structure is for the fw_cfg etc/tpm/config file.
+//
+#pragma pack (1)
+typedef struct {
+  UINT32 PpiAddress;
+  UINT8  TpmVersion;
+  UINT8  PpiVersion;
+} QEMU_FWCFG_TPM_CONFIG;
+#pragma pack ()
+
+#define QEMU_TPM_VERSION_UNSPEC    0
+#define QEMU_TPM_VERSION_1_2       1
+#define QEMU_TPM_VERSION_2         2
+
+#define QEMU_TPM_PPI_VERSION_NONE  0
+#define QEMU_TPM_PPI_VERSION_1_30  1
+
+#endif
Signature · 1 line
2.17.0.253.g3dd125b46d
#4 lore raw

PATCH v3 3/4 OvmfPkg: add Tcg2PhysicalPresenceLibQemu

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Cloned "SecurityPkg/Library/DxeTcg2PhysicalPresenceLib" and:

- removed all the functions that are unreachable from Tcg2PhysicalPresenceLibProcessRequest() [called from platform BDS], or SubmitRequestToPreOSFunction() and ReturnOperationResponseToOsFunction() [called from Tcg2Dxe].

- replaced everything that's related to the TCG2_PHYSICAL_PRESENCE*_VARIABLE variables, with direct access to the QEMU structures.

This commit is based on initial experimental work from Stefan Berger. In particular, he wrote most of QEMU PPI support, and designed the qemu/firmware interaction. Initially, Stefan tried to reuse the existing SecurityPkg code, but we eventually decided to get rid of the variables and simplify the ovmf/qemu version.

Contributed-under: TianoCore Contribution Agreement 1.1

---
 OvmfPkg/OvmfPkgIa32.dsc                                                                                                        |   2 +-
 OvmfPkg/OvmfPkgIa32X64.dsc                                                                                                     |   2 +-
 OvmfPkg/OvmfPkgX64.dsc                                                                                                         |   2 +-
 {SecurityPkg/Library/DxeTcg2PhysicalPresenceLib => OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu}/DxeTcg2PhysicalPresenceLib.inf |  46 +-
 OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c                                                       | 919 ++++++++++++++++++++
 {SecurityPkg/Library/DxeTcg2PhysicalPresenceLib => OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu}/PhysicalPresenceStrings.uni    |  33 +-
 6 files changed, 955 insertions(+), 49 deletions(-)
OvmfPkg/OvmfPkgIa32.dsc +1 -1
index 6c361b73cd55..251434a9ff7c 100644
@@ -206,7 +206,7 @@ [LibraryClasses]
 
 !if $(TPM2_ENABLE) == TRUE
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
-  Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf
+  Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf
   Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
 !else
   Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
OvmfPkg/OvmfPkgIa32X64.dsc +1 -1
index 62a6075a671d..ce247a59d61a 100644
@@ -211,7 +211,7 @@ [LibraryClasses]
 
 !if $(TPM2_ENABLE) == TRUE
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
-  Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf
+  Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf
   Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
 !else
   Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
OvmfPkg/OvmfPkgX64.dsc +1 -1
index cbab1aa328c6..67f7e155ee3e 100644
@@ -211,7 +211,7 @@ [LibraryClasses]
 
 !if $(TPM2_ENABLE) == TRUE
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
-  Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf
+  Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf
   Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
 !else
   Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf renamed from SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf +25 -21

83 lines not on this page · raw message

OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c new file +919 -0

919 lines not on this page · raw message

OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/PhysicalPresenceStrings.uni renamed from SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/PhysicalPresenceStrings.uni +8 -25
similarity index 56%
copy from SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/PhysicalPresenceStrings.uni
copy to OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/PhysicalPresenceStrings.uni
index 0271b890e01c..67c640d2c18d 100644
@@ -2,12 +2,12 @@
   String definitions for TPM 2.0 physical presence confirm text.
 
 Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials 
-are licensed and made available under the terms and conditions of the BSD License 
-which accompanies this distribution.  The full text of the license may be found at 
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 **/
@@ -15,47 +15,30 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #langdef en-US "English"
 
 #string TPM_HEAD_STR                  #language en-US    "A configuration change was requested to %s this computer's TPM (Trusted Platform Module)\n\n"
-#string TPM_PPI_HEAD_STR              #language en-US    "A configuration change was requested to allow the Operating System to %s the computer's TPM (Trusted Platform Module) without asking for user confirmation in the future.\n\n"
 
-#string TPM_ACCEPT_KEY                #language en-US    "Press F10 " 
-#string TPM_CAUTION_KEY               #language en-US    "Press F12 " 
+#string TPM_ACCEPT_KEY                #language en-US    "Press F10 "
+#string TPM_CAUTION_KEY               #language en-US    "Press F12 "
 #string TPM_REJECT_KEY                #language en-US    "to %s the TPM \nPress ESC to reject this change request and continue\n"
 
-#string TPM_ENABLE                    #language en-US    "enable"
-#string TPM_DISABLE                   #language en-US    "disable"
 #string TPM_CLEAR                     #language en-US    "clear"
 #string TPM_SET_PCR_BANKS                       #language en-US    "change the boot measurements to use PCR bank(s) of"
 #string TPM_CHANGE_EPS                          #language en-US    "clear and change identity of"
-#string TPM_DISABLE_ENDORSEMENT_ENABLE_STORAGE  #language en-US    "disable access to some secrets stored in"
 
-#string TPM_NO_PPI_MAINTAIN           #language en-US    "maintain"
-#string TPM_NO_PPI_TURN_ON            #language en-US    "turn on"
-#string TPM_NO_PPI_TURN_OFF           #language en-US    "turn off"
 #string TPM_NO_PPI_INFO               #language en-US    "to approve future Operating System requests "
 
-#string TPM_WARNING_DISABLE           #language en-US    "WARNING: Doing so might prevent security applications that rely on the TPM from functioning as expected.\n\n"
 #string TPM_WARNING_CLEAR             #language en-US    "WARNING: Clearing erases information stored on the TPM. You will lose all created keys and access to data encrypted by these keys. "
-#string TPM_NOTE_CLEAR                #language en-US    "NOTE: This action does not clear the TPM, but by approving this configuration change, future actions to clear the TPM will not require user confirmation.\n\n"
 #string TPM_WARNING_SET_PCR_BANKS_1                     #language en-US    "WARNING: Changing the PCR bank(s) of the boot measurements may prevent the Operating System from properly processing the measurements. Please check if your Operating System supports the new PCR bank(s).\n\n"
 #string TPM_WARNING_SET_PCR_BANKS_2                     #language en-US    "WARNING: Secrets in the TPM that are bound to the boot state of your machine may become unusable.\n\n"
 #string TPM_WARNING_CHANGE_EPS_1                        #language en-US    "WARNING: Clearing erases information stored on the TPM. You will lose all created keys and access to data encrypted with these keys.\n\n"
 #string TPM_WARNING_CHANGE_EPS_2                        #language en-US    "WARNING: Changing the identity of the TPM may require additional steps to establish trust into the new identity.\n\n"
-#string TPM_WARNING_PP_CHANGE_PCRS_FALSE                #language en-US    "WARNING: Allowing future changes to format of the boot measurement log may affect the Operating System.\n\n"
-#string TPM_WARNING_PP_CHANGE_EPS_FALSE_1               #language en-US    "WARNING: Allowing future changes to the TPM's firmware may affect the operation of the TPM and may erase information stored on the TPM.\n\n"
-#string TPM_WARNING_PP_CHANGE_EPS_FALSE_2               #language en-US    "You may lose all created keys and access to data encrypted by these keys.\n\n"
-#string TPM_WARNING_DISABLE_ENDORSEMENT_ENABLE_STORAGE  #language en-US    "WARNING: Doing so might prevent security applications that rely on the TPM from functioning as expected.\n\n"
 
 #string TCG_STORAGE_HEAD_STR                  #language en-US    "A configuration change was requested to %s on subsequent boots\n\n"
-#string TCG_STORAGE_PPI_HEAD_STR              #language en-US    "A configuration change was requested to allow the Operating System to %s without asking for user confirmation in the future.\n\n"
 
-#string TCG_STORAGE_ACCEPT_KEY                #language en-US    "Press F10 " 
-#string TCG_STORAGE_CAUTION_KEY               #language en-US    "Press F12 " 
+#string TCG_STORAGE_ACCEPT_KEY                #language en-US    "Press F10 "
+#string TCG_STORAGE_CAUTION_KEY               #language en-US    "Press F12 "
 #string TCG_STORAGE_REJECT_KEY                #language en-US    "to %s\nPress ESC to reject this change request and continue\n"
 
 #string TCG_STORAGE_NO_PPI_INFO               #language en-US    "to approve future Operating System requests "
 
 #string TCG_STORAGE_ENABLE_BLOCK_SID          #language en-US    "issue a Block SID authentication command"
 #string TCG_STORAGE_DISABLE_BLOCK_SID         #language en-US    "disable issuing a Block SID authentication command"
-
-#string TCG_STORAGE_PP_ENABLE_BLOCK_SID       #language en-US    "enable blocking SID authentication"
-#string TCG_STORAGE_PP_DISABLE_BLOCK_SID      #language en-US    "disable blocking SID authentication"
Signature · 1 line
2.17.0.253.g3dd125b46d
Reviewed-by on v3 3/4
#5 lore raw

Re: [Qemu-devel] [edk2] [PATCH v3 3/4] OvmfPkg: add Tcg2PhysicalPresenceLibQemu

Quoted 7 lines · On 05/18/18 14:23, [email protected] wrote:
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c new file +7 -0
+/**
+  Initializes QEMU PPI memory region.
+
+  @retval EFI_SUCCESS           Operation completed successfully.
+  @retval EFI_PROTOCOL_ERROR    PPI address is invalid.
+**/
+STATIC

OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c line 102

Quoted 10 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c new file +10 -0
+EFI_STATUS
+QemuTpmInitPPI (
+  VOID
+  )
+{
+  EFI_STATUS                      Status;
+  QEMU_FWCFG_TPM_CONFIG           Config;
+  EFI_PHYSICAL_ADDRESS            PpiAddress64;
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+  int                             i;

(1) This should be "UINTN Idx".

Quoted 25 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c new file +25 -0
+
+  if (mPpi != NULL) {
+    return EFI_SUCCESS;
+  }
+
+  Status = QemuTpmReadConfig (&Config);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  mPpi = (QEMU_TPM_PPI *)(UINTN)Config.PpiAddress;
+  if (mPpi == NULL) {
+    return EFI_PROTOCOL_ERROR;
+  }
+
+  DEBUG ((DEBUG_INFO, "[TPM2PP] mPpi=%p version=%d\n", mPpi, Config.TpmVersion));
+
+  PpiAddress64 = (UINTN)mPpi;
+  if ((PpiAddress64 & ~(UINT64)EFI_PAGE_MASK) !=
+      ((PpiAddress64 + sizeof *mPpi - 1) & ~(UINT64)EFI_PAGE_MASK)) {
+    DEBUG ((DEBUG_ERROR, "[TPM2PP] mPpi crosses a page boundary\n"));
+    return EFI_PROTOCOL_ERROR;
+  }
+
+  Status = gDS->GetMemorySpaceDescriptor (PpiAddress64, &Descriptor);

OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c line 137

Quoted 10 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c new file +10 -0
+  if (Status != EFI_SUCCESS && Status != EFI_NOT_FOUND) {
+    ASSERT_EFI_ERROR (Status);
+    return EFI_PROTOCOL_ERROR;
+  }
+  if (Status == EFI_SUCCESS && (
+        Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo &&
+        Descriptor.GcdMemoryType != EfiGcdMemoryTypeNonExistent)) {
+    DEBUG ((DEBUG_ERROR, "[TPM2PP] mPpi has an invalid memory type\n"));
+    return EFI_PROTOCOL_ERROR;
+  }

(2) In edk2 we generally don't compare EFI_STATUS variables against EFI_SUCCESS, instead we write [!]EFI_ERROR (Status). Whether that's easier or harder to understand is anyone's guess, but either way that's the idiom.

(3) The indentation / parentheses around "Descriptor.GcdMemoryType" aren't idiomatic.

(4) I think the new checks introduce a new logic bug in this patch -- if we return EFI_PROTOCOL_ERROR, we should re-set mPpi to NULL. Otherwise the next call to QemuTpmInitPPI() will succeed, using a bogus mPpi value.

OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c line 141

Quoted 4 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c new file +4 -0
+
+  for (i = 0; i < sizeof (mPpi->Func); i++) {
+    mPpi->Func[i] = 0;
+  }

(5) Functionally this is OK, because mPpi->Func has UINT8 elements; however we should really use ARRAY_SIZE() here.

Quoted 12 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c new file +12 -0
+  if (Config.TpmVersion == QEMU_TPM_VERSION_2) {
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_NO_ACTION] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_CLEAR] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_CHANGE_EPS] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID] = TPM_PPI_FLAGS;
+    mPpi->Func[TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID] = TPM_PPI_FLAGS;
+  }

OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c line 163

Quoted 10 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c new file +10 -0
+
+  if (mPpi->In == 0) {
+    mPpi->In = 1;
+    mPpi->Request = TCG2_PHYSICAL_PRESENCE_NO_ACTION;
+    mPpi->LastRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION;
+    mPpi->NextStep = TCG2_PHYSICAL_PRESENCE_NO_ACTION;
+  }
+
+  return EFI_SUCCESS;
+}

Thus, I've squashed the following patch into yours, and build-tested it:

Quoted 47 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c +10 -10
index cc4046228ba3..52913f573676 100644
@@ -99,7 +99,7 @@ QemuTpmInitPPI (
   QEMU_FWCFG_TPM_CONFIG           Config;
   EFI_PHYSICAL_ADDRESS            PpiAddress64;
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
-  int                             i;
+  UINTN                           Idx;
 
   if (mPpi != NULL) {
     return EFI_SUCCESS;
@@ -121,23 +121,23 @@ QemuTpmInitPPI (
   if ((PpiAddress64 & ~(UINT64)EFI_PAGE_MASK) !=
       ((PpiAddress64 + sizeof *mPpi - 1) & ~(UINT64)EFI_PAGE_MASK)) {
     DEBUG ((DEBUG_ERROR, "[TPM2PP] mPpi crosses a page boundary\n"));
-    return EFI_PROTOCOL_ERROR;
+    goto InvalidPpiAddress;
   }
 
   Status = gDS->GetMemorySpaceDescriptor (PpiAddress64, &Descriptor);
-  if (Status != EFI_SUCCESS && Status != EFI_NOT_FOUND) {
+  if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
     ASSERT_EFI_ERROR (Status);
-    return EFI_PROTOCOL_ERROR;
+    goto InvalidPpiAddress;
   }
-  if (Status == EFI_SUCCESS && (
-        Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo &&
-        Descriptor.GcdMemoryType != EfiGcdMemoryTypeNonExistent)) {
+  if (!EFI_ERROR (Status) &&
+      (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo &&
+       Descriptor.GcdMemoryType != EfiGcdMemoryTypeNonExistent)) {
     DEBUG ((DEBUG_ERROR, "[TPM2PP] mPpi has an invalid memory type\n"));
-    return EFI_PROTOCOL_ERROR;
+    goto InvalidPpiAddress;
   }
 
-  for (i = 0; i < sizeof (mPpi->Func); i++) {
-    mPpi->Func[i] = 0;
+  for (Idx = 0; Idx < ARRAY_SIZE (mPpi->Func); Idx++) {
+    mPpi->Func[Idx] = 0;
   }
   if (Config.TpmVersion == QEMU_TPM_VERSION_2) {
     mPpi->Func[TCG2_PHYSICAL_PRESENCE_NO_ACTION] = TPM_PPI_FLAGS;

OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c QemuTpmInitPPI ( · line 167

Quoted 8 lines
OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c +4 -0
@@ -160,6 +160,10 @@ QemuTpmInitPPI (
   }
 
   return EFI_SUCCESS;
+
+InvalidPpiAddress:
+  mPpi = NULL;
+  return EFI_PROTOCOL_ERROR;
 }

With that:

Thanks
Laszlo

#6 lore raw

PATCH v3 4/4 OvmfPkg/PlatformBootManagerLib: process TPM PPI request

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

Call Tcg2PhysicalPresenceLibProcessRequest() to process pending PPI requests from PlatformBootManagerAfterConsole().

Laszlo understanding of edk2 is that the PPI operation processing was meant to occur *entirely* before End-Of-Dxe, so that 3rd party UEFI drivers couldn't interfere with PPI opcode processing *at all*.

He suggested that we should *not* call Tcg2PhysicalPresenceLibProcessRequest() from BeforeConsole(). Because, an "auth" console, i.e. one that does not depend on a 3rd party driver, is *in general* impossible to guarantee. Instead we could opt to trust 3rd party drivers, and use the "normal" console(s) in AfterConsole(), in order to let the user confirm the PPI requests. It will depend on the user to enable Secure Boot, so that the trustworthiness of those 3rd party drivers is ensured. If an attacker roots the guest OS from within, queues some TPM2 PPI requests, and also modifies drivers on the EFI system partition and/or in GPU option ROMs (?), then those drivers will not load after guest reboot, and thus the dependent console(s) won't be used for confirming the PPI requests.

Contributed-under: TianoCore Contribution Agreement 1.1

---
 OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 2 ++
 OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c              | 6 ++++++
 2 files changed, 8 insertions(+)
OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +2 -0
index 27789b7377bc..4b72c44bcf0a 100644
@@ -38,6 +38,7 @@ [Packages]
   IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
   SourceLevelDebugPkg/SourceLevelDebugPkg.dec
   OvmfPkg/OvmfPkg.dec
+  SecurityPkg/SecurityPkg.dec
 
 [LibraryClasses]
   BaseLib
@@ -56,6 +57,7 @@ [LibraryClasses]
   LoadLinuxLib
   QemuBootOrderLib
   UefiLib
+  Tcg2PhysicalPresenceLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent
OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c +6 -0
index 004b753f4d26..aa036bbba567 100644
@@ -16,6 +16,7 @@
 #include <Guid/XenInfo.h>
 #include <Guid/RootBridgesConnectedEventGroup.h>
 #include <Protocol/FirmwareVolume2.h>
+#include <Library/Tcg2PhysicalPresenceLib.h>
 
 
 //
@@ -1410,6 +1411,11 @@ PlatformBootManagerAfterConsole (
   //
   PciAcpiInitialization ();
 
+  //
+  // Process TPM PPI request
+  //
+  Tcg2PhysicalPresenceLibProcessRequest (NULL);
+
   //
   // Process QEMU's -kernel command line option
   //
Signature · 1 line
2.17.0.253.g3dd125b46d
#7 lore raw
In reply to [email protected]
Quoted 18 lines · On 05/18/2018 08:23 AM, [email protected] wrote:

From: Marc-André Lureau <[email protected]>

Hi,

The following series adds basic TPM PPI 1.3 support for OVMF-on-QEMU with TPM2 (I haven't looked at TPM1, for lack of interest).

PPI test runs successfully with Windows 10 WHLK, despite the limited number of supported funcions (tpm2_ppi_funcs table, in particular, no function allows to manipulate Tcg2PhysicalPresenceFlags)

The way it works is relatively simple: a memory region is allocated by QEMU to save PPI related variables. An ACPI interface is exposed by QEMU to let the guest manipulate those. At boot, ovmf processes and updates the PPI qemu region and request variables.

I build edk2 with:

Quoted 7 lines
$ build -DTPM2_ENABLE

I test with qemu & swtpm/libtpms (tpm2 branches, swtpm_setup.sh --tpm2
--tpm-state tpmstatedir)

$ swtpm socket --tpmstate tpmstatedir --ctrl type=unixio,path=tpmsock
   --tpm2 &

Make this:

swtpm socket --tpmstate dir=tpmstatedir --ctrl type=unixio,path=tpmsock --tpm2

Quoted 54 lines
$ qemu .. -chardev socket,id=chrtpm,path=tpmsock -tpmdev
   emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0

Github trees:
https://github.com/elmarco/edk2/tree/tpm-ppi
https://github.com/elmarco/qemu/tree/tpm-ppi

Thanks

v3: after Laszlo review
- dropped DxeTcg2PhysicalPresenceLib.uni
- removed mTpm2PPIFuncs static initialization, use hard-coded assignments
- declared STATIC the functions that should be
- fixed an OUT/IN decorator
- use EFI_PROTOCOL_ERROR instead of EFI_INVALID_PARAMETER when PPI initialization fails
- replaced EFI_D_INFO with DEBUG_INFO
- added a check for mPpi address that it doesn't cross a page boundary
- added a GetMemorySpaceDescriptor() check for memory type
- declared *mPpi as volatile, to correct mmio access
- a few more style changes
- comments updated
- some minor dead code/inclusion/defines removal
- added a few r-b tags

v2:
- style and commit message fixes

Marc-André Lureau (4):
OvmfPkg: add Tcg2PhysicalPresenceLibNull when !TPM2_ENABLE OvmfPkg/IndustryStandard: add QemuTpm.h header
OvmfPkg: add Tcg2PhysicalPresenceLibQemu OvmfPkg/PlatformBootManagerLib: process TPM PPI request

  OvmfPkg/OvmfPkgIa32.dsc                       |   4 +-
  OvmfPkg/OvmfPkgIa32X64.dsc                    |   4 +-
  OvmfPkg/OvmfPkgX64.dsc                        |   4 +-
  .../PlatformBootManagerLib.inf                |   2 +
  .../DxeTcg2PhysicalPresenceLib.inf            |  33 +
  .../DxeTcg2PhysicalPresenceLib.inf            |  46 +-
  OvmfPkg/Include/IndustryStandard/QemuTpm.h    |  69 ++
  .../PlatformBootManagerLib/BdsPlatform.c      |   6 +
  .../DxeTcg2PhysicalPresenceLib.c              |  20 +-
  .../DxeTcg2PhysicalPresenceLib.c              | 919 ++++++++++++++++++
  .../PhysicalPresenceStrings.uni               |  33 +-
  11 files changed, 1081 insertions(+), 59 deletions(-)

create mode 100644 OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
copy {SecurityPkg/Library/DxeTcg2PhysicalPresenceLib => OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu}/DxeTcg2PhysicalPresenceLib.inf (66%) create mode 100644 OvmfPkg/Include/IndustryStandard/QemuTpm.h
copy EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ia32/CpuSleep.c => OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.c (55%) create mode 100644 OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c
copy {SecurityPkg/Library/DxeTcg2PhysicalPresenceLib => OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu}/PhysicalPresenceStrings.uni (56%)

#8 lore raw
In reply to [email protected]
Quoted 70 lines · On 05/18/18 14:23, [email protected] wrote:

From: Marc-André Lureau <[email protected]>

Hi,

The following series adds basic TPM PPI 1.3 support for OVMF-on-QEMU with TPM2 (I haven't looked at TPM1, for lack of interest).

PPI test runs successfully with Windows 10 WHLK, despite the limited number of supported funcions (tpm2_ppi_funcs table, in particular, no function allows to manipulate Tcg2PhysicalPresenceFlags)

The way it works is relatively simple: a memory region is allocated by QEMU to save PPI related variables. An ACPI interface is exposed by QEMU to let the guest manipulate those. At boot, ovmf processes and updates the PPI qemu region and request variables.

I build edk2 with:

$ build -DTPM2_ENABLE

I test with qemu & swtpm/libtpms (tpm2 branches, swtpm_setup.sh --tpm2
--tpm-state tpmstatedir)

$ swtpm socket --tpmstate tpmstatedir --ctrl type=unixio,path=tpmsock
  --tpm2 &
$ qemu .. -chardev socket,id=chrtpm,path=tpmsock -tpmdev
  emulator,id=tpm0,chardev=chrtpm -device tpm-crb,tpmdev=tpm0

Github trees:
https://github.com/elmarco/edk2/tree/tpm-ppi
https://github.com/elmarco/qemu/tree/tpm-ppi

Thanks

v3: after Laszlo review
- dropped DxeTcg2PhysicalPresenceLib.uni
- removed mTpm2PPIFuncs static initialization, use hard-coded assignments
- declared STATIC the functions that should be
- fixed an OUT/IN decorator
- use EFI_PROTOCOL_ERROR instead of EFI_INVALID_PARAMETER when PPI initialization fails
- replaced EFI_D_INFO with DEBUG_INFO
- added a check for mPpi address that it doesn't cross a page boundary
- added a GetMemorySpaceDescriptor() check for memory type
- declared *mPpi as volatile, to correct mmio access
- a few more style changes
- comments updated
- some minor dead code/inclusion/defines removal
- added a few r-b tags

v2:
- style and commit message fixes

Marc-André Lureau (4):
OvmfPkg: add Tcg2PhysicalPresenceLibNull when !TPM2_ENABLE OvmfPkg/IndustryStandard: add QemuTpm.h header
OvmfPkg: add Tcg2PhysicalPresenceLibQemu OvmfPkg/PlatformBootManagerLib: process TPM PPI request

 OvmfPkg/OvmfPkgIa32.dsc                       |   4 +-
 OvmfPkg/OvmfPkgIa32X64.dsc                    |   4 +-
 OvmfPkg/OvmfPkgX64.dsc                        |   4 +-
 .../PlatformBootManagerLib.inf                |   2 +
 .../DxeTcg2PhysicalPresenceLib.inf            |  33 +
 .../DxeTcg2PhysicalPresenceLib.inf            |  46 +-
 OvmfPkg/Include/IndustryStandard/QemuTpm.h    |  69 ++
 .../PlatformBootManagerLib/BdsPlatform.c      |   6 +
 .../DxeTcg2PhysicalPresenceLib.c              |  20 +-
 .../DxeTcg2PhysicalPresenceLib.c              | 919 ++++++++++++++++++
Quoted 9 lines
 .../PhysicalPresenceStrings.uni               |  33 +-
 11 files changed, 1081 insertions(+), 59 deletions(-)
 create mode 100644 OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
 copy {SecurityPkg/Library/DxeTcg2PhysicalPresenceLib => OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu}/DxeTcg2PhysicalPresenceLib.inf (66%)
 create mode 100644 OvmfPkg/Include/IndustryStandard/QemuTpm.h
 copy EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ia32/CpuSleep.c => OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.c (55%)
 create mode 100644 OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c
 copy {SecurityPkg/Library/DxeTcg2PhysicalPresenceLib => OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu}/PhysicalPresenceStrings.uni (56%)

I briefly summarized the updates that I mentioned in review on the patches themselves, and pushed the series as commit range 75135cc6988e..8d65d3b25e35.

Thank you guys again!
Laszlo