summaryrefslogtreecommitdiff
path: root/Core/EM/TCG2
diff options
context:
space:
mode:
authorraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
committerraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
commitb7c51c9cf4864df6aabb99a1ae843becd577237c (patch)
treeeebe9b0d0ca03062955223097e57da84dd618b9a /Core/EM/TCG2
downloadzprj-b7c51c9cf4864df6aabb99a1ae843becd577237c.tar.xz
init. 1AQQW051HEADmaster
Diffstat (limited to 'Core/EM/TCG2')
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm20CRBLib.c171
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm20CRBLib.cif13
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm20CRBLib.h140
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm20CRBLib.mak87
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm20CRBLib.sdl61
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm2PttHciDeviceLib.c707
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm2PttHciDeviceLib.h170
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm2PttHciRegs.h99
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.cif12
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.mak52
-rw-r--r--Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.sdl20
-rw-r--r--Core/EM/TCG2/Common/AmiTcgNvflagSample.c580
-rw-r--r--Core/EM/TCG2/Common/AmiTcgNvflagSample.cif12
-rw-r--r--Core/EM/TCG2/Common/AmiTcgNvflagSample.dxs44
-rw-r--r--Core/EM/TCG2/Common/AmiTcgNvflagSample.h199
-rw-r--r--Core/EM/TCG2/Common/AmiTcgNvflagSample.mak75
-rw-r--r--Core/EM/TCG2/Common/AmiTcgNvflagSample.sdl66
-rw-r--r--Core/EM/TCG2/Common/Common.cif21
-rw-r--r--Core/EM/TCG2/Common/CommonHeaders.cif19
-rw-r--r--Core/EM/TCG2/Common/EMpCallBin.asm337
-rw-r--r--Core/EM/TCG2/Common/EMpCallBin32.asm251
-rw-r--r--Core/EM/TCG2/Common/EMpTcmDxe.c482
-rw-r--r--Core/EM/TCG2/Common/EMpTcmPei.c691
-rw-r--r--Core/EM/TCG2/Common/PPI/TcgService/TcgService.c64
-rw-r--r--Core/EM/TCG2/Common/PPI/TcgService/TcgService.h122
-rw-r--r--Core/EM/TCG2/Common/PPI/TcgService/TcgTcmService.c73
-rw-r--r--Core/EM/TCG2/Common/PPI/TcgService/TcgTcmService.h181
-rw-r--r--Core/EM/TCG2/Common/PPI/TcgService_PPI.cif11
-rw-r--r--Core/EM/TCG2/Common/PPI/TpmDevice/TpmDevice.c97
-rw-r--r--Core/EM/TCG2/Common/PPI/TpmDevice/TpmDevice.h179
-rw-r--r--Core/EM/TCG2/Common/PPI/TpmDevice_PPI.cif9
-rw-r--r--Core/EM/TCG2/Common/Protocol/TcgService/TcgService.c66
-rw-r--r--Core/EM/TCG2/Common/Protocol/TcgService/TcgService.h171
-rw-r--r--Core/EM/TCG2/Common/Protocol/TcgService/TcgTcmService.c75
-rw-r--r--Core/EM/TCG2/Common/Protocol/TcgService/TcgTcmService.h167
-rw-r--r--Core/EM/TCG2/Common/Protocol/TcgService_Protocol.cif11
-rw-r--r--Core/EM/TCG2/Common/Protocol/TpmDevice/TpmDevice.c60
-rw-r--r--Core/EM/TCG2/Common/Protocol/TpmDevice/TpmDevice.h197
-rw-r--r--Core/EM/TCG2/Common/Protocol/TpmDevice_Protocol.cif9
-rw-r--r--Core/EM/TCG2/Common/TCGMisc.h822
-rw-r--r--Core/EM/TCG2/Common/TCGSmm/TCGSmm.DXS84
-rw-r--r--Core/EM/TCG2/Common/TCGSmm/TCGSmm.c956
-rw-r--r--Core/EM/TCG2/Common/TCGSmm/TCGSmm.cif12
-rw-r--r--Core/EM/TCG2/Common/TCGSmm/TCGSmm.h104
-rw-r--r--Core/EM/TCG2/Common/TCGSmm/TCGSmm.mak101
-rw-r--r--Core/EM/TCG2/Common/TCGSmm/TCGSmm.sdl24
-rw-r--r--Core/EM/TCG2/Common/TcgCRBPei.c537
-rw-r--r--Core/EM/TCG2/Common/TcgDxe.c2187
-rw-r--r--Core/EM/TCG2/Common/TcgDxe.cif17
-rw-r--r--Core/EM/TCG2/Common/TcgDxe.dxs110
-rw-r--r--Core/EM/TCG2/Common/TcgDxe.mak196
-rw-r--r--Core/EM/TCG2/Common/TcgDxe.sdl27
-rw-r--r--Core/EM/TCG2/Common/TcgDxe20.c853
-rw-r--r--Core/EM/TCG2/Common/TcgLegacy.c977
-rw-r--r--Core/EM/TCG2/Common/TcgLegacy.cif12
-rw-r--r--Core/EM/TCG2/Common/TcgLegacy.dxs71
-rw-r--r--Core/EM/TCG2/Common/TcgLegacy.h213
-rw-r--r--Core/EM/TCG2/Common/TcgLegacy.mak104
-rw-r--r--Core/EM/TCG2/Common/TcgLegacy.sdl36
-rw-r--r--Core/EM/TCG2/Common/TcgPei.cif18
-rw-r--r--Core/EM/TCG2/Common/TcgPei.dxs114
-rw-r--r--Core/EM/TCG2/Common/TcgPei.mak123
-rw-r--r--Core/EM/TCG2/Common/TcgPei.sdl34
-rw-r--r--Core/EM/TCG2/Common/TcgPeiAfterMem.c492
-rw-r--r--Core/EM/TCG2/Common/TcgPeiAfterMem.cif11
-rw-r--r--Core/EM/TCG2/Common/TcgPeiAfterMem.mak149
-rw-r--r--Core/EM/TCG2/Common/TcgPrivate.c70
-rw-r--r--Core/EM/TCG2/Common/TcgPrivate.h400
-rw-r--r--Core/EM/TCG2/Common/TcgTcmPei.c476
-rw-r--r--Core/EM/TCG2/Common/TcgTcmPeiAfterMem.c538
-rw-r--r--Core/EM/TCG2/Common/TcgTisPei.c538
-rw-r--r--Core/EM/TCG2/Common/TisPei.c691
-rw-r--r--Core/EM/TCG2/Common/Tpm20Includes/Tpm20.h1917
-rw-r--r--Core/EM/TCG2/Common/Tpm20Includes/Tpm20Includes.cif10
-rw-r--r--Core/EM/TCG2/Common/Tpm20Includes/Tpm20Pei.h32
-rw-r--r--Core/EM/TCG2/Common/Tpm20Includes/TrEEProtocol.h152
-rw-r--r--Core/EM/TCG2/Common/TpmDxe.c545
-rw-r--r--Core/EM/TCG2/Common/xTcgDxe.c1835
-rw-r--r--Core/EM/TCG2/Common/xTcgPei.c317
-rw-r--r--Core/EM/TCG2/Common/xTcgPeiAfterMem.c284
-rw-r--r--Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.cif10
-rw-r--r--Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.libbin0 -> 39300 bytes
-rw-r--r--Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.sdl27
-rw-r--r--Core/EM/TCG2/CommonLibraries/ShaLib/ShaLibPei.libbin0 -> 36454 bytes
-rw-r--r--Core/EM/TCG2/Libraries.cif10
-rw-r--r--Core/EM/TCG2/TCG2.chmbin0 -> 132919 bytes
-rw-r--r--Core/EM/TCG2/Tcg.cif13
-rw-r--r--Core/EM/TCG2/Tcg.sdl646
-rw-r--r--Core/EM/TCG2/TisLib/INTTcgAcpi.h114
-rw-r--r--Core/EM/TCG2/TisLib/TcgCommon.c808
-rw-r--r--Core/EM/TCG2/TisLib/TcgCommon.h305
-rw-r--r--Core/EM/TCG2/TisLib/TcgEFI12.h186
-rw-r--r--Core/EM/TCG2/TisLib/TcgEfiTpm.h220
-rw-r--r--Core/EM/TCG2/TisLib/TcgPc.h311
-rw-r--r--Core/EM/TCG2/TisLib/TcgTpm12.h1973
-rw-r--r--Core/EM/TCG2/TisLib/TcmPc.h153
-rw-r--r--Core/EM/TCG2/TisLib/TisLib.cif23
-rw-r--r--Core/EM/TCG2/TisLib/TisLib.mak116
-rw-r--r--Core/EM/TCG2/TisLib/TisLib.sdl46
-rw-r--r--Core/EM/TCG2/TisLib/TpmLib.c614
-rw-r--r--Core/EM/TCG2/TisLib/TpmLib.h136
-rw-r--r--Core/EM/TCG2/TisLib/ZTEICTcmOrdinals.h203
-rw-r--r--Core/EM/TCG2/TisLib/sha.h122
-rw-r--r--Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.c125
-rw-r--r--Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.cif12
-rw-r--r--Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.dxs68
-rw-r--r--Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.h74
-rw-r--r--Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.mak91
-rw-r--r--Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.sdl71
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.c132
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.cif17
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.dxs75
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.h69
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.mak107
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.sdl41
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackSmiFlash.c160
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.c584
-rw-r--r--Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.h198
118 files changed, 29850 insertions, 0 deletions
diff --git a/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.c b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.c
new file mode 100644
index 0000000..81a086d
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.c
@@ -0,0 +1,171 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/Tpm20CRBLib/Tpm20CRBLib.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/Tpm20CRBLib/Tpm20CRBLib.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 3 3/14/14 3:19p Fredericko
+//
+// 2 3/11/14 6:02p Fredericko
+// [TAG] EIP151925
+// [Category] New Feature
+// [Description] Changes for TcgGeneric Regression Testing
+//
+// 1 10/08/13 11:59a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 1:48p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name:
+//
+// Description:
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+#include <Efi.h>
+#include "Tpm20CRBLib.h"
+#include "AmiLib.h"
+#include <token.h>
+#include <Tpm20Includes\Tpm20.h>
+
+
+//Forward declare functions
+#if FTpmPlatformProfile == 1
+
+EFI_STATUS
+iTpmGetResponse (
+ IN OUT VOID *ResponseBuffer,
+ IN OUT UINT32 *ResponseSize
+ );
+
+EFI_STATUS
+iTpmSendCommand (
+ IN VOID *CommandBuffer,
+ IN UINT32 CommandSize
+ );
+
+EFI_STATUS
+CheckPspDevicePresent (
+ VOID
+ );
+
+#else
+
+EFI_STATUS
+EFIAPI
+PttHciReceive(
+ OUT UINT8 *FtpmBuffer,
+ OUT UINT32 *RespSize
+ );
+
+EFI_STATUS
+EFIAPI
+PttHciSend(
+ IN UINT8 *FtpmBuffer,
+ IN UINT32 DataLength
+ );
+
+BOOLEAN
+EFIAPI
+PttHciPresenceCheck();
+
+
+#endif
+
+BOOLEAN isTpm20CrbPresent()
+{
+ #if FTpmPlatformProfile == 1
+ if(!EFI_ERROR(CheckPspDevicePresent()))return TRUE;
+ return FALSE;
+ #else
+ return (PttHciPresenceCheck());
+ #endif
+}
+
+
+EFI_STATUS
+EFIAPI
+CrbSend(
+ IN UINT8 *InputBuffer,
+ IN UINT32 DataLength
+)
+{
+ #if FTpmPlatformProfile == 1
+ return(iTpmSendCommand(InputBuffer, DataLength));
+ #else
+ return (PttHciSend(InputBuffer, DataLength));
+ #endif
+}
+
+
+EFI_STATUS
+EFIAPI
+CrbReceive(
+ OUT UINT8 *OutBuffer,
+ OUT UINT32 *RespSize
+)
+{
+ #if FTpmPlatformProfile == 1
+ return(iTpmGetResponse(OutBuffer, RespSize));
+ #else
+ return (PttHciReceive(OutBuffer, RespSize));
+ #endif
+}
+
+EFI_STATUS
+EFIAPI
+CrbSubmitCmd(
+ IN UINT8 *InputBuffer,
+ IN UINT32 InputBufferSize,
+ OUT UINT8 *OutputBuffer,
+ OUT UINT32 *OutputBufferSize
+ )
+{
+ EFI_STATUS Status;
+
+ if(InputBuffer == NULL || OutputBuffer == NULL || InputBufferSize == 0){
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = CrbSend(InputBuffer, InputBufferSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ ///
+ /// Receive the response data from TPM
+ ///
+ Status = CrbReceive(OutputBuffer, OutputBufferSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ return Status;
+}
diff --git a/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.cif b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.cif
new file mode 100644
index 0000000..5476df6
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.cif
@@ -0,0 +1,13 @@
+<component>
+ name = "Tpm20CRBLib"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\CRB_lib"
+ RefName = "Tpm20CRBLib"
+[files]
+"Tpm20CRBLib.mak"
+"Tpm20CRBLib.c"
+"Tpm20CRBLib.h"
+"Tpm20CRBLib.sdl"
+[parts]
+"Tpm2PttLibrary"
+<endComponent>
diff --git a/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.h b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.h
new file mode 100644
index 0000000..1182ab2
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.h
@@ -0,0 +1,140 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/Tpm20CRBLib/Tpm20CRBLib.h 2 6/14/14 12:24a Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 6/14/14 12:24a $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/Tpm20CRBLib/Tpm20CRBLib.h $
+//
+// 2 6/14/14 12:24a Fredericko
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:59a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 9/16/13 1:51p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name:
+//
+// Description:
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+#include <Efi.h>
+#include <token.h>
+
+
+//Defines ACPI Interface for Control Resource Buffer Access
+#define TPM20H2NS(x) ((((x) << 8) | ((x) >> 8)) & 0xffff)
+#define TPM20H2NL(x) (TPM20H2NS ((x) >> 16) | (TPM20H2NS ((x) & 0xffff) << 16))
+
+#define CONTROL_AREA_RSVD 0x00
+#define CONTROL_AREA_ERROR 0x04
+#define CONTROL_AREA_CANCEL 0x08
+#define CONTROL_AREA_START 0x0C
+#define CONTROL_AREA_INT 0x10
+#define CONTROL_AREA_CMD_SZ 0x18
+#define CONTROL_AREA_CMD_BASE 0x1C
+#define CONTROL_AREA_RSP_SZ 0x24
+#define CONTROL_AREA_RSP_BASE 0x28
+
+//Timeouts
+#define TIMEOUT_A 500 ///< 500 microseconds
+#define TIMEOUT_B 500 * 1000 ///< 10ms (max command processing time in PK-TPM ca. 3ms)
+#define TIMEOUT_C 1000 * 1000 ///< 1s
+#define TIMEOUT_D 500 * 1000 ///< 500 ms
+#define POLLING_PERIOD 140 ///< Poll register every 140 microsecondss
+
+#define CRB_DEVICE_CMD 0x40
+#define CRB_DEVICE_STS 0x44
+
+#define TPM20_CRB_IDLE 0x02
+
+#define TPM20_MAX_COMMAND_SIZE 0x0F80
+#define StartStatusFieldSet 0x00000001
+
+#define TPM20_CRB_CMD_BASE 0x80
+#define TPM20_CRB_RSP_BASE 0x80
+
+#define TPM20_CRBSTATUS_START 0x00000001
+#define TPM20_CRB_ALL_CLEAR 0xFFFFFFFF
+
+#define RESPONSE_HEADER_SIZE 0x0a
+
+
+#pragma pack(1)
+
+typedef struct _STATUS_FIELD_
+{
+ UINT32 Rsvd;
+ UINT32 Error;
+ UINT32 Cancel;
+ UINT32 Start;
+}STATUS_FIELD;
+
+typedef struct _CONTROL_AREA_LAYOUT_
+{
+ STATUS_FIELD StatusFieled;
+ UINT64 IntCntrl;
+ UINT32 Cmd_Sz;
+ UINT64 Cmd_Addrs;
+ UINT32 Rsp_Sz;
+ UINT64 Rsp_Addrs;
+}CONTROL_AREA_LAYOUT;
+
+typedef struct _GENERIC_RESP_HDR_
+{
+ UINT16 Tag;
+ UINT32 RespSize;
+ UINT32 RespCode;
+}GENERIC_RESP_HDR;
+
+#pragma pack()
+
+
+EFI_STATUS
+EFIAPI
+CrbSubmitCmd(
+ IN UINT8 *InputBuffer,
+ IN UINT32 InputBufferSize,
+ OUT UINT8 *OutputBuffer,
+ OUT UINT32 *OutputBufferSize);
+
+BOOLEAN isTpm20CrbPresent();
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//********************************************************************** \ No newline at end of file
diff --git a/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.mak b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.mak
new file mode 100644
index 0000000..3fa1f66
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.mak
@@ -0,0 +1,87 @@
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
+#**********************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/Tpm20CRBLib/Tpm20CRBLib.mak 1 4/21/14 2:15p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:15p $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/Tpm20CRBLib/Tpm20CRBLib.mak $
+#
+# 1 4/21/14 2:15p Fredericko
+#
+# 3 3/14/14 3:20p Fredericko
+#
+# 2 3/11/14 6:01p Fredericko
+# [TAG] EIP151925
+# [Category] New Feature
+# [Description] Changes for TcgGeneric Regression Testing
+#
+# 1 10/08/13 11:59a Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 2 10/03/13 1:48p Fredericko
+#
+# 1 7/10/13 5:50p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+#
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: Tpm20CrbLib.mak
+#
+# Description: Make file for the Tpm20CrbLib component
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+Tpm20Crb_lib : $(BUILD_DIR)\Tpm20CRBLib.mak make_crb_lib make_crb_Peilib
+$(BUILD_DIR)\Tpm20CRBLib.lib: Tpm20Crb_lib
+$(BUILD_DIR)\IA32\Tpm20CRBLib.lib: Tpm20Crb_lib
+
+$(BUILD_DIR)\Tpm20CRBLib.mak : $(TPM20_CRBLIB)\Tpm20CrbLib.cif $(TPM20_CRBLIB)\Tpm20CrbLib.mak $(BUILD_RULES)
+ $(CIF2MAK) $(TPM20_CRBLIB)\Tpm20CrbLib.cif $(CIF2MAK_DEFAULTS)
+
+LIB_CFLAGS=$(CFLAGS)\
+ /I$(TPM20_CRBLIB)\
+ /I$(TCG_DIR)\Common\
+ /I$(TPM20_CRBLIB)\
+ /I$(TCG_DIR)\
+
+TCG_LIB_LITE_OBJS = \
+$(BUILD_DIR)\$(TPM20_CRBLIB)\Tpm20CrbLib.obj
+
+
+make_crb_lib: $(SHALIB) $(FWTPM20LIBx64)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\Tpm20CrbLib.mak all\
+ "CFLAGS=$(LIB_CFLAGS) "\
+ TYPE=LIBRARY
+
+make_crb_Peilib: $(SHALIBPEI) $(FWTPM20LIBx32)
+!IF "$(PROCESSOR)"=="x64"
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS) BUILD_DIR=$(BUILD_DIR)\IA32\
+ /f $(BUILD_DIR)\Tpm20CrbLib.mak all\
+ "CFLAGS=$(LIB_CFLAGS) "\
+ TYPE=PEI_LIBRARY
+!ELSE
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TisLib.mak all\
+ "CFLAGS=$(LIB_CFLAGS) "\
+ TYPE=PEI_LIBRARY
+!ENDIF \ No newline at end of file
diff --git a/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.sdl b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.sdl
new file mode 100644
index 0000000..27c38ed
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm20CRBLib.sdl
@@ -0,0 +1,61 @@
+TOKEN
+ Name = "TPM20CRB_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable TCG support in Project"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Master = Yes
+End
+
+PATH
+ Name = "TPM20_CRBLIB"
+ Help = "Tcg Directory"
+End
+
+MODULE
+ Help = "Includes TCG.mak to Project"
+ File = "Tpm20CRBLib.mak"
+End
+
+TOKEN
+ Name = "FTpmPlatformProfile"
+ Value = "0"
+ Help = "Set to 0 for Intel PTT and 1 for AMD PSP device"
+ TokenType = BOOLEAN
+ TargetMAK = Yes
+ TargetH = Yes
+END
+
+TOKEN
+ Name = "TPM20_CRBBASE"
+ Value = "0x0FED70000"
+ Help = "Start of Mem I/O region dedicated for TPM access"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "FWTPM20LIBx32"
+ Value = " $(BUILD_DIR)\IA32\Tpm2PttLibrary.lib"
+ TokenType = Expression
+ TargetMAK = Yes
+ Token = "x64_BUILD" "=" "1"
+End
+
+TOKEN
+ Name = "FWTPM20LIBx32"
+ Value = " $(BUILD_DIR)\Tpm2PttLibrary.lib"
+ TokenType = Expression
+ TargetMAK = Yes
+ Token = "x64_BUILD" "=" "0"
+End
+
+TOKEN
+ Name = "FWTPM20LIBx64"
+ Value = "$(BUILD_DIR)\Tpm2PttLibrary.lib"
+ TokenType = Expression
+ TargetMAK = Yes
+End
diff --git a/Core/EM/TCG2/CRB_lib/Tpm2PttHciDeviceLib.c b/Core/EM/TCG2/CRB_lib/Tpm2PttHciDeviceLib.c
new file mode 100644
index 0000000..edf31ac
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm2PttHciDeviceLib.c
@@ -0,0 +1,707 @@
+/** @file
+ Implements Platform Trust Technology (FTPM) HCI Device Library.
+
+@copyright
+ Copyright (c) 2012 - 2013 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+ This file contains an 'Intel Peripheral Driver' and uniquely
+ identified as "Intel Reference Module" and is
+ licensed for Intel CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+
+**/
+#include <efi.h>
+#include <AmiLib.h>
+#include "Tpm2PttHciRegs.h"
+#include "Tpm2PttHciDeviceLib.h"
+#include <Tpm20Includes\Tpm20.h>
+//#include <EfiCommonLib.h>
+
+
+#ifndef ASSERT
+#define ASSERT(Condition) if(!(Condition)) { \
+ EFI_DEADLOOP() \
+ }
+#endif
+
+#define MmioAddress(BaseAddr, Register) \
+ ( (UINTN)BaseAddr + (UINTN)(Register) )
+
+#define Mmio32Ptr(BaseAddr, Register) \
+ ( (volatile UINT32 *)MmioAddress(BaseAddr, Register) )
+
+#define Mmio32(BaseAddr, Register) \
+ *Mmio32Ptr(BaseAddr, Register)
+
+#define MmioRead32(Addr) \
+ Mmio32(Addr, 0)
+
+#define MmioWrite32(Addr, Value) \
+ (Mmio32(Addr, 0) = (UINT32)Value)
+
+#define TPM_H2NS( x ) \
+ (((UINT16)(x) << 8) | ((UINT16)(x) >> 8))
+#define TPM_H2NL( x ) \
+ (UINT32)((((UINT32)(x)) >> 24) \
+ | (((x) >> 8) & 0xff00) \
+ | ((x) << 24) \
+ | (((x) & 0xff00) << 8))
+
+#define TPM_N2HS( x ) TPM_H2NS( x )
+#define TPM_N2HL( x ) TPM_H2NL( x )
+
+#pragma pack (push, 1)
+typedef struct {
+ TPM_ST tag;
+ UINT32 paramSize;
+ TPM_RC responseCode;
+} TPM2_RESPONSE_HEADER;
+#pragma pack (pop)
+
+#define EFI_MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
+
+
+#ifdef INT_EFI_DEBUG
+/**
+ Prints command or response buffer for debugging purposes.
+
+ @param[in] Buffer Buffer to print.
+ @param[in] BufferSize Buffer data length.
+**/
+VOID
+EFIAPI
+PttHciPrintBuffer(IN UINT8 *Buffer, IN UINT32 BufferSize)
+{
+ UINT32 Index;
+
+ DEBUG ((EFI_D_INFO, "Buffer Address: 0x%08x, Size: 0x%08x, Value:\n", Buffer, BufferSize));
+ for(Index = 0; Index < BufferSize; Index++){
+ DEBUG ((EFI_D_INFO, "%02x ", *(Buffer + Index)));
+ if((Index+1) % 16 == 0) DEBUG ((EFI_D_INFO, "\n"));
+ }
+ DEBUG ((EFI_D_INFO, "\n"));
+}
+#endif // EFI_DEBUG
+
+
+VOID MicroSecDelay (
+ UINTN Delay
+)
+{
+ UINTN Counter, i;
+ UINT32 Data32, PrevData;
+ UINTN Remainder;
+
+ Counter = (UINTN)Div64 ((UINT64)(Delay * 10), 3, &Remainder);
+ if (Remainder != 0) {
+ Counter++;
+ }
+ //
+ // Call WaitForTick for Counter + 1 ticks to try to guarantee Counter tick
+ // periods, thus attempting to ensure Microseconds of stall time.
+ //
+ if (Counter != 0) {
+
+ PrevData = IoRead32(PM_BASE_ADDRESS + 8);
+ for (i = 0; i < Counter; ) {
+ Data32 = IoRead32(PM_BASE_ADDRESS + 8);
+ if (Data32 < PrevData) { // Reset if there is a overlap
+ PrevData=Data32;
+ continue;
+ }
+ i += (Data32 - PrevData);
+ PrevData = Data32;
+ }
+ }
+ return;
+}
+
+
+/**
+ Copy data from the MMIO region to system memory by using 32-bit access.
+
+ Copy data from the MMIO region specified by starting address StartAddress
+ to system memory specified by Buffer by using 32-bit access. The total
+ number of byte to be copied is specified by Length. Buffer is returned.
+
+ If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
+
+ If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
+ If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+ If Length is not aligned on a 32-bit boundary, then ASSERT().
+ If Buffer is not aligned on a 32-bit boundary, then ASSERT().
+
+ @param StartAddress The starting address for the MMIO region to be copied from.
+ @param Length The size, in bytes, of Buffer.
+ @param Buffer The pointer to a system memory buffer receiving the data read.
+
+ @return Buffer
+**/
+UINT32 *
+EFIAPI
+MmioReadBuffer32 (
+ IN UINTN StartAddress,
+ IN UINTN Length,
+ OUT UINT32 *Buffer
+ )
+{
+ UINT32 *ReturnBuffer;
+
+ ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);
+
+ ASSERT ((Length - 1) <= (EFI_MAX_ADDRESS - StartAddress));
+ ASSERT ((Length - 1) <= (EFI_MAX_ADDRESS - (UINTN) Buffer));
+
+ ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);
+ ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);
+
+ ReturnBuffer = Buffer;
+
+ while (Length != 0) {
+ *(Buffer++) = MmioRead32 (StartAddress);
+ StartAddress += sizeof (UINT32);
+ Length -= sizeof (UINT32);
+ }
+
+ return ReturnBuffer;
+}
+
+/**
+ Copy data from system memory to the MMIO region by using 32-bit access.
+
+ Copy data from system memory specified by Buffer to the MMIO region specified
+ by starting address StartAddress by using 32-bit access. The total number
+ of byte to be copied is specified by Length. Buffer is returned.
+
+ If StartAddress is not aligned on a 32-bit boundary, then ASSERT().
+
+ If Length is greater than (MAX_ADDRESS - StartAddress + 1), then ASSERT().
+ If Length is greater than (MAX_ADDRESS -Buffer + 1), then ASSERT().
+
+ If Length is not aligned on a 32-bit boundary, then ASSERT().
+
+ If Buffer is not aligned on a 32-bit boundary, then ASSERT().
+
+ @param StartAddress The starting address for the MMIO region to be copied to.
+ @param Length The size, in bytes, of Buffer.
+ @param Buffer The pointer to a system memory buffer containing the data to write.
+
+ @return Buffer
+**/
+UINT32 *
+EFIAPI
+MmioWriteBuffer32 (
+ IN UINTN StartAddress,
+ IN UINTN Length,
+ IN CONST UINT32 *Buffer
+ )
+{
+ UINT32 *ReturnBuffer;
+
+ ASSERT ((StartAddress & (sizeof (UINT32) - 1)) == 0);
+
+ ASSERT ((Length - 1) <= (EFI_MAX_ADDRESS - StartAddress));
+ ASSERT ((Length - 1) <= (EFI_MAX_ADDRESS - (UINTN) Buffer));
+
+ ASSERT ((Length & (sizeof (UINT32) - 1)) == 0);
+ ASSERT (((UINTN) Buffer & (sizeof (UINT32) - 1)) == 0);
+
+ ReturnBuffer = (UINT32 *) Buffer;
+
+ while (Length != 0) {
+ MmioWrite32 (StartAddress, *(Buffer++));
+
+ StartAddress += sizeof (UINT32);
+ Length -= sizeof (UINT32);
+ }
+
+ return ReturnBuffer;
+}
+
+/**
+ Checks whether FTPM is enabled (FTPM_STS::FTPM_EN).
+
+ @retval TRUE FTPM is enabled.
+ @retval FALSE FTPM is disabled. All LT writes will be dropped.
+ All LT reads will be returned with read data value of all 0’s.
+ The bit can only be written once per ME power cycle.
+
+**/
+BOOLEAN
+EFIAPI
+PttHciPresenceCheck (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: PttHciPresenceCheck start\n"));
+
+ DEBUG ((EFI_D_INFO, "Check FTPM_STS - ENABLED bit (@ 0x%08x)\n", (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_STS)));
+#endif
+ Status = PttHciWaitRegisterBits(
+ (EFI_PHYSICAL_ADDRESS)(UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_STS),
+ B_PTT_HCI_STS_ENABLED,
+ V_PTT_HCI_IGNORE_BITS,
+ PTT_HCI_TIMEOUT_A
+ );
+ if(Status == EFI_SUCCESS){
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/**
+ Checks whether PTT is Ready
+
+ @retval TRUE PTT is ready.
+ @retval FALSE PTT is not ready
+
+**/
+BOOLEAN
+EFIAPI
+PttHciReadyCheck (
+ VOID
+ )
+{
+ UINT32 RegRead;
+
+ RegRead = MmioRead32 ((UINTN) ( R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_STS ));
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "Check PTT_STS - READY bit (@ 0x%08x)\n", RegRead));
+#endif
+
+ if(( B_PTT_HCI_STS_READY & RegRead) != 0){
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/**
+ Checks whether TPM2_Startup command has been executed (FTPM_STS::STARTUP_EXEC).
+ If command was executed, it should not be redundantly issued again.
+
+ @retval TRUE Startup command executed already.
+ @retval FALSE Startup command not executed yet.
+
+**/
+BOOLEAN
+EFIAPI
+PttHciStartupExecuted (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: PttHciStartupExecuted start\n"));
+ DEBUG ((EFI_D_INFO, "Check FTPM_STS - STARTUP_EXECECUTED bit (@ 0x%08x)\n", (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_STS)));
+#endif
+ Status = PttHciWaitRegisterBits(
+ (EFI_PHYSICAL_ADDRESS)(UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_STS),
+ B_PTT_HCI_STS_STARTUP_EXEC,
+ V_PTT_HCI_IGNORE_BITS,
+ PTT_HCI_TIMEOUT_A
+ );
+ if(Status == EFI_SUCCESS){
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/**
+ Sets FTPM_CMD and CA_START register to a defined value to indicate that a command is
+ available for processing.
+ Any host write to this register shall result in an interrupt to the ME firmware.
+
+ @retval EFI_SUCCESS Register successfully written.
+ @retval TBD
+
+**/
+EFI_STATUS
+EFIAPI
+PttHciRequestCommandExec (
+ VOID
+ )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: PttHciRequestCommandExec start\n"));
+
+ DEBUG ((EFI_D_INFO, "Command ready for processing - write 0x%08x to FTPM_CA_START register (@ 0x%08x)\n",
+ V_PTT_HCI_COMMAND_AVAILABLE_START,
+ (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_START)));
+#endif
+ MmioWrite32((UINTN)R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_START, V_PTT_HCI_COMMAND_AVAILABLE_START);
+
+ ///
+ /// Write 0x1 to HCI CMD register to indicate that a command is available for processing
+ ///
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "Command ready for processing - write 0x%08x to FTPM_CMD register (@ 0x%08x)\n",
+ V_PTT_HCI_COMMAND_AVAILABLE_CMD,
+ (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CMD)));
+#endif
+ MmioWrite32((UINTN)R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CMD, V_PTT_HCI_COMMAND_AVAILABLE_CMD);
+
+ return Status;
+}
+
+/**
+ Checks whether the value of a FTPM register satisfies the input BIT setting.
+
+ @param[in] Register Address port of register to be checked.
+ @param[in] BitSet Check these data bits are set.
+ @param[in] BitClear Check these data bits are clear.
+ @param[in] TimeOut The max wait time (unit MicroSecond) when checking register.
+
+ @retval EFI_SUCCESS The register satisfies the check bit.
+ @retval EFI_TIMEOUT The register can't run into the expected status in time.
+**/
+EFI_STATUS
+EFIAPI
+PttHciWaitRegisterBits(
+ IN EFI_PHYSICAL_ADDRESS RegAddress,
+ IN UINT32 BitSet,
+ IN UINT32 BitClear,
+ IN UINT32 TimeOut
+ )
+{
+ UINT32 RegRead;
+ UINT32 WaitTime;
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: PttHciWaitRegisterBits start\n"));
+#endif
+
+ for (WaitTime = 0; WaitTime < TimeOut; WaitTime += PTT_HCI_POLLING_PERIOD){
+ RegRead = MmioRead32 ((UINTN)RegAddress);
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "RegRead: 0x%08x, BitSetMask: 0x%08x, BitClearMask: 0x%08x, WaitTime: %d (microsec)\n", RegRead, BitSet, BitClear, WaitTime));
+#endif
+
+ if (RegRead == 0xFFFFFFFF)
+ continue;
+
+ if ((RegRead & BitSet) == BitSet && (RegRead & BitClear) == 0) {
+ return EFI_SUCCESS;
+ }
+// MicroSecondDelay (PTT_HCI_POLLING_PERIOD); Override
+ MicroSecDelay(PTT_HCI_POLLING_PERIOD);
+ }
+ return EFI_TIMEOUT;
+}
+
+/**
+ Sends command to FTPM for execution.
+
+ @param[in] FtpmBuffer Buffer for TPM command data.
+ @param[in] DataLength TPM command data length.
+
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_TIMEOUT The register can't run into the expected status in time.
+**/
+EFI_STATUS
+EFIAPI
+PttHciSend(
+ IN UINT8 *FtpmBuffer,
+ IN UINT32 DataLength
+ )
+{
+ EFI_STATUS Status;
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: PttHciSend start\n"));
+#endif
+ Status = PttHciWaitRegisterBits(
+ (EFI_PHYSICAL_ADDRESS)(UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_START),
+ V_PTT_HCI_IGNORE_BITS,
+ V_PTT_HCI_START_CLEAR,
+ PTT_HCI_TIMEOUT_A
+ );
+
+ if(EFI_ERROR (Status)){
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_ERROR, "FTPM_CA_START register not clear - TPM2 command cannot be sent! EFI_ERROR = %r\n", Status));
+#endif
+ return EFI_NOT_READY;
+ }
+ ///
+ /// Align command size to dword before writing to FTPM_CRB
+ ///
+ if(DataLength % 4 != 0){
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "Alignment: DataLength change from %d ", DataLength));
+#endif
+ DataLength += (4 - (DataLength % 4));
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "to %d\n", DataLength));
+#endif
+ }
+
+ MmioWriteBuffer32((UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CRB), (UINTN)DataLength, (UINT32*)FtpmBuffer);
+
+ ///
+ /// FTPM_CA_CMD - the physical address to which the TPM 2.0 driver will write the command to execute
+ ///
+ MmioWrite32((UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_CMD), R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CRB);
+ MmioWrite32((UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_CMD_SZ), S_PTT_HCI_CRB_LENGTH);
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "FTPM_CA_CMD (@ 0x%08x) written, value = 0x%08x\n",
+ (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_CMD),
+ R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CRB));
+ DEBUG ((EFI_D_INFO, "FTPM_CA_CMD_SZ (@ 0x%08x) written, value = 0x%08x\n",
+ (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_CMD_SZ), DataLength));
+#endif
+
+ ///
+ /// Set FTPM_CMD and FTPM_CA_START registers to indicate TPM command ready for execution
+ ///
+ Status = PttHciRequestCommandExec();
+#ifdef INT_EFI_DEBUG
+ if(Status == EFI_SUCCESS){
+ DEBUG ((EFI_D_INFO, "FTPM_CMD register written - TPM2 command available for processing\n"));
+ }
+#endif
+
+ return Status;
+}
+
+/**
+ Receives response data of last command from FTPM.
+
+ @param[out] FtpmBuffer Buffer for response data.
+ @param[out] RespSize Response data length.
+
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_TIMEOUT The register can't run into the expected status in time.
+ @retval EFI_DEVICE_ERROR Unexpected device status.
+ @retval EFI_BUFFER_TOO_SMALL Response data is too long.
+**/
+EFI_STATUS
+EFIAPI
+PttHciReceive(
+ OUT UINT8 *FtpmBuffer,
+ OUT UINT32 *RespSize
+ )
+{
+ EFI_STATUS Status;
+ UINT16 Data16;
+ UINT32 Data32;
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: PttHciReceive start\n"));
+#endif
+
+ ///
+ /// Wait for the command completion - poll FTPM_CA_START clear
+ ///
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: Check Start status (FTPM_CA_START)\n"));
+#endif
+ Status = PttHciWaitRegisterBits(
+ (EFI_PHYSICAL_ADDRESS)(UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_START),
+ V_PTT_HCI_IGNORE_BITS,
+ V_PTT_HCI_START_CLEAR,
+ PTT_HCI_TIMEOUT_D
+ );
+ if(EFI_ERROR (Status)){
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_ERROR, "FTPM_CA_START register not clear - TPM2 response cannot be read! EFI_ERROR = %r\n", Status));
+#endif
+ goto Exit;
+ }
+
+ ///
+ /// Check for error condition - FTPM_CA_ERROR
+ ///
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: Check Error status (FTPM_CA_ERROR)\n"));
+#endif
+ Status = PttHciWaitRegisterBits(
+ (EFI_PHYSICAL_ADDRESS)(UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_ERROR),
+ V_PTT_HCI_IGNORE_BITS,
+ V_PTT_HCI_ALL_BITS_CLEAR,
+ PTT_HCI_TIMEOUT_A
+ );
+ if(EFI_ERROR (Status)){
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_ERROR, "FTPM_CA_ERROR register set - TPM2 response cannot be provided! EFI_ERROR = %r\n", Status));
+#endif
+ Status = EFI_DEVICE_ERROR;
+ goto Exit;
+ }
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "FTPM_CA_START register clear - TPM2 command processing completed - ready to read\n"));
+#endif
+
+ ///
+ /// Read the response data header
+ ///
+ MmioReadBuffer32((UINTN)R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CRB, PTT_HCI_RESPONSE_HEADER_SIZE, (UINT32*)FtpmBuffer);
+
+ ///
+ /// Check the reponse data header (tag, parasize and returncode)
+ ///
+ MemCpy (&Data16, FtpmBuffer, sizeof (UINT16));
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "TPM2_RESPONSE_HEADER.tag = 0x%04x\n", TPM_H2NS(Data16)));
+#endif
+
+ ///
+ /// TPM Rev 2.0 Part 2 - 6.9 TPM_ST (Structure Tags)
+ /// TPM_ST_RSP_COMMAND - Used in a response that has an error in the tag.
+ ///
+ if (TPM_H2NS(Data16) == TPM_ST_RSP_COMMAND) {
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_ERROR, "TPM2_RESPONSE_HEADER.tag = TPM_ST_RSP_COMMAND - Error in response!\n"));
+#endif
+ Status = EFI_DEVICE_ERROR;
+ goto Exit;
+ }
+
+ MemCpy(&Data32, (FtpmBuffer + 2), sizeof(UINT32));
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "TPM2_RESPONSE_HEADER.paramSize = 0x%08x\n", TPM_H2NL(Data32)));
+#endif
+
+ *RespSize = TPM_H2NL(Data32);
+
+ if(*RespSize == sizeof(TPM2_RESPONSE_HEADER)) {
+ Status = EFI_SUCCESS;
+ goto Exit;
+ }
+ if(*RespSize < sizeof(TPM2_RESPONSE_HEADER)) {
+ Status = EFI_DEVICE_ERROR;
+ goto Exit;
+ }
+ if(*RespSize > S_PTT_HCI_CRB_LENGTH) {
+ Status = EFI_BUFFER_TOO_SMALL;
+ goto Exit;
+ }
+
+ ///
+ /// Align command size to dword before writing to FTPM_CRB
+ ///
+ if(*RespSize % 4 != 0){
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "Alignment: RespSize change from %d ", *RespSize));
+#endif
+ *RespSize += (4 - (*RespSize % 4));
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "to %d\n", *RespSize));
+#endif
+ }
+
+ ///
+ /// Reading the entire response data
+ ///
+ MmioReadBuffer32((UINTN)R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CRB, *RespSize, (UINT32*)FtpmBuffer);
+
+ Exit:
+ if(!EFI_ERROR(Status)){
+ ///
+ /// FTPM_CA_CMD - the physical address from which the TPM 2.0 driver will read command responses
+ ///
+ MmioWrite32((UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_RSP), R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CRB);
+ MmioWrite32((UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_RSP_SZ),S_PTT_HCI_CRB_LENGTH);
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "FTPM_CA_RSP (@ 0x%08x) written, value = 0x%08x\n",
+ (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_RSP),
+ (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CRB)));
+ DEBUG ((EFI_D_INFO, "FTPM_CA_RSP_SZ (@ 0x%08x) written, value = 0x%08x\n",
+ (R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_CA_RSP_SZ), *RespSize));
+#endif
+ }
+
+ return Status;
+}
+
+/**
+ Sends formatted command to FTPM for execution and returns formatted response data.
+
+ @param[in] InputBuffer Buffer for the input data.
+ @param[in] InputBufferSize Size of the input buffer.
+ @param[out] ReturnBuffer Buffer for the output data.
+ @param[out] ReturnBufferSize Size of the output buffer.
+
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_TIMEOUT The register can't run into the expected status in time.
+**/
+EFI_STATUS
+EFIAPI
+PttHciSubmitCommand(
+ IN UINT8 *InputBuffer,
+ IN UINT32 InputBufferSize,
+ OUT UINT8 *ReturnBuffer,
+ OUT UINT32 *ReturnBufferSize
+ )
+{
+ EFI_STATUS Status;
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: PttHciSubmitCommand start\n"));
+#endif
+
+ if(!PttHciReadyCheck()){
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_ERROR, "PTT device not ready. \n"));
+#endif
+ return EFI_NOT_READY;
+ }
+
+ if(InputBuffer == NULL || ReturnBuffer == NULL || InputBufferSize == 0){
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_ERROR, "Buffer == NULL or InputBufferSize == 0\n"));
+#endif
+ return EFI_INVALID_PARAMETER;
+ }
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: Command Buffer dump\n"));
+#endif
+
+ ///
+ /// Send the command to TPM
+ ///
+ Status = PttHciSend(InputBuffer, InputBufferSize);
+ if (EFI_ERROR (Status)) {
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_ERROR, "FTpmHciSend EFI_ERROR = %r\n", Status));
+#endif
+ return Status;
+ }
+
+ ///
+ /// Receive the response data from TPM
+ ///
+ Status = PttHciReceive(ReturnBuffer, ReturnBufferSize);
+ if (EFI_ERROR (Status)) {
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_ERROR, "FTpmHciReceive EFI_ERROR = %r\n", Status));
+#endif
+ return Status;
+ }
+
+#ifdef INT_EFI_DEBUG
+ DEBUG ((EFI_D_INFO, "PTT: Response Buffer dump\n"));
+#endif
+
+ return Status;
+}
+
diff --git a/Core/EM/TCG2/CRB_lib/Tpm2PttHciDeviceLib.h b/Core/EM/TCG2/CRB_lib/Tpm2PttHciDeviceLib.h
new file mode 100644
index 0000000..bcb204f
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm2PttHciDeviceLib.h
@@ -0,0 +1,170 @@
+/** @file
+ Platform Trust Technology (FTPM) HCI Device Library
+
+@copyright
+ Copyright (c) 2012 -2013 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+ This file contains an 'Intel Peripheral Driver' and uniquely
+ identified as "Intel Reference Module" and is
+ licensed for Intel CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+**/
+#ifndef _TPM2_PTT_HCI_DEVICE_LIB_H_
+#define _TPM2_PTT_HCI_DEVICE_LIB_H_
+
+#include <Efi.h>
+
+///
+/// Default Timeout values
+///
+#define PTT_HCI_TIMEOUT_A 500 ///< 500 microseconds
+// AMI-Core Override for PTT +
+//#define PTT_HCI_TIMEOUT_B 10 * 1000 ///< 10ms (max command processing time in PK-TPM ca. 3ms)
+#define PTT_HCI_TIMEOUT_B 500 * 1000 ///< 10ms (max command processing time in PK-TPM ca. 3ms)
+// AMI-Core Override for PTT -
+#define PTT_HCI_TIMEOUT_C 1000 * 1000 ///< 1s
+#define PTT_HCI_TIMEOUT_D 500 * 1000 ///< 500 ms
+#define PTT_HCI_POLLING_PERIOD 140 ///< Poll register every 140 microsecondss
+
+/// TPM2_RESPONSE_HEADER size (10B) aligned to dword
+#define PTT_HCI_RESPONSE_HEADER_SIZE 12 ///< 12B
+
+/**
+ Checks whether FTPM is enabled (FTPM_STS::FTPM_EN).
+
+ @retval TRUE FTPM is enabled.
+ @retval FALSE FTPM is disabled. All LT writes will be dropped.
+ All LT reads will be returned with read data value of all 0’s.
+ The bit can only be written once per ME power cycle.
+**/
+BOOLEAN
+EFIAPI
+PttHciPresenceCheck (
+ VOID
+ );
+
+/**
+ Checks whether TPM2_Startup command has been executed (FTPM_STS::STARTUP_EXEC).
+ If command was executed, it should not be redundantly issued again.
+
+ @retval TRUE Startup command executed already.
+ @retval FALSE Startup command not executed yet.
+**/
+BOOLEAN
+EFIAPI
+PttHciStartupExecuted (
+ VOID
+ );
+
+/**
+ Sets FTPM_CMD and CA_START register to a defined value to indicate that a command is
+ available for processing.
+ Any host write to this register shall result in an interrupt to the ME firmware.
+
+ @retval EFI_SUCCESS Register successfully written.
+ @retval TBD
+**/
+EFI_STATUS
+EFIAPI
+PttHciRequestCommandExec (
+ VOID
+ );
+
+/**
+ Checks whether the value of a FTPM register satisfies the input BIT setting.
+
+ @param[in] Register Address port of register to be checked.
+ @param[in] BitSet Check these data bits are set.
+ @param[in] BitClear Check these data bits are clear.
+ @param[in] TimeOut The max wait time (unit MicroSecond) when checking register.
+
+ @retval EFI_SUCCESS The register satisfies the check bit.
+ @retval EFI_TIMEOUT The register can't run into the expected status in time.
+**/
+EFI_STATUS
+EFIAPI
+PttHciWaitRegisterBits(
+ IN EFI_PHYSICAL_ADDRESS RegAddress,
+ IN UINT32 BitSet,
+ IN UINT32 BitClear,
+ IN UINT32 TimeOut
+ );
+
+/**
+ Sends command to FTPM for execution.
+
+ @param[in] FtpmBuffer Buffer for TPM command data.
+ @param[in] DataLength TPM command data length.
+
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_TIMEOUT The register can't run into the expected status in time.
+**/
+EFI_STATUS
+EFIAPI
+PttHciSend(
+ IN UINT8 *FtpmBuffer,
+ IN UINT32 DataLength
+ );
+
+/**
+ Receives response data of last command from FTPM.
+
+ @param[out] FtpmBuffer Buffer for response data.
+ @param[out] RespSize Response data length.
+
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_TIMEOUT The register can't run into the expected status in time.
+ @retval EFI_DEVICE_ERROR Unexpected device status.
+ @retval EFI_BUFFER_TOO_SMALL Response data is too long.
+**/
+EFI_STATUS
+EFIAPI
+PttHciReceive(
+ OUT UINT8 *FtpmBuffer,
+ OUT UINT32 *RespSize
+ );
+
+/**
+ Sends formatted command to FTPM for execution and returns formatted response data.
+
+ @param[in] InputBuffer Buffer for the input data.
+ @param[in] InputBufferSize Size of the input buffer.
+ @param[out] ReturnBuffer Buffer for the output data.
+ @param[out] ReturnBufferSize Size of the output buffer.
+
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_TIMEOUT The register can't run into the expected status in time.
+**/
+EFI_STATUS
+EFIAPI
+PttHciSubmitCommand(
+ IN UINT8 *InputBuffer,
+ IN UINT32 InputBufferSize,
+ OUT UINT8 *ReturnBuffer,
+ OUT UINT32 *ReturnBufferSize
+ );
+
+/**
+ Checks whether PTT is Ready
+
+ @retval TRUE PTT is ready.
+ @retval FALSE PTT is not ready
+
+**/
+BOOLEAN
+EFIAPI
+PttHciReadyCheck (
+ VOID
+ );
+
+
+#endif
diff --git a/Core/EM/TCG2/CRB_lib/Tpm2PttHciRegs.h b/Core/EM/TCG2/CRB_lib/Tpm2PttHciRegs.h
new file mode 100644
index 0000000..1d1a484
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm2PttHciRegs.h
@@ -0,0 +1,99 @@
+/** @file
+ Register definitions for PTT HCI (Platform Trust Technology - Host Controller Interface).
+
+ Conventions:
+
+ - Prefixes:
+ Definitions beginning with "R_" are registers
+ Definitions beginning with "B_" are bits within registers
+ Definitions beginning with "V_" are meaningful values of bits within the registers
+ Definitions beginning with "S_" are register sizes
+ Definitions beginning with "N_" are the bit position
+
+@copyright
+ Copyright (c) 2012 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+ This file contains an 'Intel Peripheral Driver' and uniquely
+ identified as "Intel Reference Module" and is
+ licensed for Intel CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+**/
+#ifndef _TPM2_PTT_HCI_REGS_H_
+#define _TPM2_PTT_HCI_REGS_H_
+
+
+///
+/// FTPM HCI register base address
+///
+#define R_PTT_HCI_BASE_ADDRESS 0xFED70000
+
+//
+// FTPM HCI Control Area
+//
+#define R_PTT_HCI_CA_RSVD 0x00
+#define R_PTT_HCI_CA_ERROR 0x04
+#define R_PTT_HCI_CA_CANCEL 0x08
+#define R_PTT_HCI_CA_START 0x0C
+#define R_PTT_HCI_CA_INT_RSVD 0x10
+#define R_PTT_HCI_CA_CMD_SZ 0x18
+#define R_PTT_HCI_CA_CMD 0x1C
+#define R_PTT_HCI_CA_RSP_SZ 0x24
+#define R_PTT_HCI_CA_RSP 0x28
+
+//
+// FTPM HCI Private Area
+//
+#define R_PTT_HCI_CMD 0x40
+#define R_PTT_HCI_STS 0x44
+
+///
+/// FTPM HCI Command and Response Buffer
+///
+#define R_PTT_HCI_CRB 0x80
+
+//
+// R_PTT_HCI_STS Flags
+//
+#define B_PTT_HCI_STS_ENABLED 0x00000001 ///< BIT0
+#define B_PTT_HCI_STS_READY 0x00000002 ///< BIT1
+#define B_PTT_HCI_STS_ACM_AS_CRTM 0x00000004 ///< BIT2
+#define B_PTT_HCI_STS_STARTUP_EXEC 0x00000008 ///< BIT3
+
+//
+// Value written to R_PTT_HCI_CMD and CA_START
+// to indicate that a command is available for processing
+//
+#define V_PTT_HCI_COMMAND_AVAILABLE_START 0x00000001
+#define V_PTT_HCI_COMMAND_AVAILABLE_CMD 0x00000000
+#define V_PTT_HCI_BUFFER_ADDRESS_RDY 0x00000003
+
+///
+/// Ignore bit setting mask for WaitRegisterBits
+///
+#define V_PTT_HCI_IGNORE_BITS 0x00000000
+
+///
+/// All bits clear mask for WaitRegisterBits
+///
+#define V_PTT_HCI_ALL_BITS_CLEAR 0xFFFFFFFF
+#define V_PTT_HCI_START_CLEAR 0x00000001
+
+///
+/// Max FTPM command/reponse buffer length
+///
+#define S_PTT_HCI_CRB_LENGTH 3968 ///< 0xFED70080:0xFED70FFF = 3968 Bytes
+// AMI-Core Override for PTT +
+#define PM_BASE_ADDRESS 0x1800
+// AMI-Core Override for PTT -
+
+
+#endif
diff --git a/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.cif b/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.cif
new file mode 100644
index 0000000..c2c3718
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.cif
@@ -0,0 +1,12 @@
+<component>
+ name = "Tpm2PttLibrary"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\CRB_lib"
+ RefName = "Tpm2PttLibrary"
+[files]
+"Tpm2PttLibrary.sdl"
+"Tpm2PttLibrary.mak"
+"Tpm2PttHciDeviceLib.h"
+"Tpm2PttHciDeviceLib.c"
+"Tpm2PttHciRegs.h"
+<endComponent>
diff --git a/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.mak b/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.mak
new file mode 100644
index 0000000..1c2be5c
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.mak
@@ -0,0 +1,52 @@
+# /*++
+# Copyright (c) 2009 Intel Corporation. All rights reserved.
+# This software and associated documentation (if any) is furnished
+# under a license and may only be used or copied in accordance
+# with the terms of the license. Except as permitted by such
+# license, no part of this software or documentation may be
+# reproduced, stored in a retrieval system, or transmitted in any
+# form or by any means without the express written consent of
+# Intel Corporation.
+# --*/
+# MAK file for the ModulePart:AtDxeLib
+Tpm2PttLibrary_Lib : $(BUILD_DIR)\Tpm2PttLibrary.mak Tpm2PttDxeLibBin Tpm2PttPeiLibBin
+$(BUILD_DIR)\Tpm2PttLibrary.lib: Tpm2PttLibrary_Lib
+$(BUILD_DIR)\IA32\Tpm2PttLibrary.lib: Tpm2PttLibrary_Lib
+
+$(BUILD_DIR)\Tpm2PttLibrary.mak : $(Tpm2PttLibrary_DIR)\Tpm2PttLibrary.cif $(Tpm2PttLibrary_DIR)\Tpm2PttLibrary.mak $(BUILD_RULES)
+ $(CIF2MAK) $(Tpm2PttLibrary_DIR)\Tpm2PttLibrary.cif $(CIF2MAK_DEFAULTS)
+
+LIB_CFLAGS=$(CFLAGS)\
+ /I$(TPM20_CRBLIB)\
+ /I$(TCG_DIR)\Common\
+ /I$(Tpm2PttLibrary_DIR)\
+ /I$(TCG_DIR)\
+
+Tpm2PttDxeLibBin :
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\Tpm2PttLibrary.mak all \
+ "CFLAGS=$(LIB_CFLAGS) "\
+ LIBRARY_NAME=$(BUILD_DIR)\Tpm2PttLibrary.lib\
+ TYPE=LIBRARY
+
+
+Tpm2PttPeiLibBin :
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS) BUILD_DIR=$(BUILD_DIR)\IA32\
+ /f $(BUILD_DIR)\Tpm2PttLibrary.mak all \
+ "CFLAGS=$(LIB_CFLAGS) "\
+ TYPE=PEI_LIBRARY
+
+
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2006, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 6145-F Northbelt Pkwy, Norcross, GA 30071 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
diff --git a/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.sdl b/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.sdl
new file mode 100644
index 0000000..1432273
--- /dev/null
+++ b/Core/EM/TCG2/CRB_lib/Tpm2PttLibrary.sdl
@@ -0,0 +1,20 @@
+TOKEN
+ Name = "Tpm2PttLibrary_SUPPORT"
+ Value = "1"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ Master = Yes
+ Help = "This driver will work for Intel FTPM only"
+End
+
+PATH
+ Name = "Tpm2PttLibrary_DIR"
+ Help = "Path"
+End
+
+
+MODULE
+ Help = "Includes Tpm2PttLibrary.mak to Project"
+ File = "Tpm2PttLibrary.mak"
+End
diff --git a/Core/EM/TCG2/Common/AmiTcgNvflagSample.c b/Core/EM/TCG2/Common/AmiTcgNvflagSample.c
new file mode 100644
index 0000000..5fffccd
--- /dev/null
+++ b/Core/EM/TCG2/Common/AmiTcgNvflagSample.c
@@ -0,0 +1,580 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/AmiTcgNvflagSample/AmiTcgNvflagSample.c 1 4/21/14 2:17p Fredericko $Revision:
+//
+// $Date:
+//*************************************************************************
+// Revision History
+// ----------------
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: AmiTcgNvflagSample
+//
+// Description: This is a sample file for support TCG Ppi. It creates and installed
+// a protocal to access the persistent bios tpm flags in Tpm NV 0x50010000.
+// See Ppi Spec 1.2
+//
+//<AMI_FHDR_END>
+//************************************************************************
+#include "AmiTcgNvflagSample.h"
+#include <EFI.h>
+#include "TcgEFI12.h"
+#include "TcgPc.h"
+#include <TcgCommon.h>
+
+
+
+EFI_GUID gEfiTpmDxeDeviceProtocolGuid = EFI_TPM_DEVICE_PROTOCOL_GUID;
+EFI_GUID gEfiTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID;
+UINT8 Internal_flag = 0;
+
+UINT32
+NvSendTpmCommand (
+ IN EFI_TCG_PROTOCOL *tcg,
+ IN UINT32 ord,
+ IN int dataSize,
+ IN VOID *data
+);
+
+
+TPM_RESULT SendSelfTest()
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ EFI_TCG_PROTOCOL *tcgSvc;
+ TPM_RESULT tpmResult = 0;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+
+ Status = pBS->LocateProtocol( &gEfiTpmDxeDeviceProtocolGuid,NULL, &TpmDevice);
+ if ( EFI_ERROR( Status ))
+ {
+ return 0;
+ }
+
+ Status = pBS->LocateProtocol( &gEfiTcgProtocolGuid, NULL, &tcgSvc );
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS, "Error: failed to locate TCG protocol: %r\n"));
+ return 0;
+ }
+
+#if defined DONT_SEND_SELFTEST_TILL_READY_TO_BOOT && DONT_SEND_SELFTEST_TILL_READY_TO_BOOT == 1
+ TpmDevice->Init( TpmDevice );
+
+ if(*(UINT16 *)(UINTN)(PORT_TPM_IOMEMBASE + 0xF00) == SELF_TEST_VID)
+ {
+ tpmResult = NvSendTpmCommand( tcgSvc, TPM_ORD_ContinueSelfTest,0, 0);
+ }
+
+ TpmDevice->Close( TpmDevice );
+#endif
+ return tpmResult;
+}
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: Set_Persistent_Bios_TPM_Flags
+//
+// Description: Sets persistent bios flags in TPM NV
+//
+//
+// Input: IN PERSISTENT_BIOS_TPM_FLAGS *
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS Set_Persistent_Bios_TPM_Flags(PERSISTENT_BIOS_TPM_FLAGS *NvBIOSflags)
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ TPM_NV_WRITE_CMD WriteCmd;
+ TPM_NV_WRITE_RET WriteRet;
+ EFI_TCG_PROTOCOL *tcgSvc;
+ TPM_RESULT RetCode;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+ UINTN Count = 10;
+
+ if(NvBIOSflags == NULL)return EFI_INVALID_PARAMETER;
+
+ Status = pBS->LocateProtocol( &gEfiTpmDxeDeviceProtocolGuid,NULL, &TpmDevice);
+ if ( EFI_ERROR( Status ))
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ Status = pBS->LocateProtocol( &gEfiTcgProtocolGuid, NULL, &tcgSvc );
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS, "Error: failed to locate TCG protocol: %r\n"));
+ return EFI_NOT_FOUND;
+ }
+
+ SendSelfTest();
+
+ TpmDevice->Init( TpmDevice );
+
+ //physical presence is required so tcgpei should have already taken care of
+ //physical presence requirement
+ WriteCmd.writeHeader.dataSize = TPM_H2NL( NV_DATA_SIZE );
+ WriteCmd.writeHeader.tag = TPM_H2NS(TPM_TAG_RQU_COMMAND);
+ WriteCmd.writeHeader.paramSize = TPM_H2NL( sizeof(TPM_NV_WRITE_CMD_HDR) + NV_DATA_SIZE);
+ WriteCmd.writeHeader.ordinal = TPM_H2NL(TPM_ORD_NV_WriteValue);
+ WriteCmd.writeHeader.nvIndex = TPM_H2NL(0x50010000);
+ WriteCmd.writeHeader.offset = TPM_H2NL(0x00000000);
+
+ pBS->SetMem(WriteCmd.data, NV_DATA_SIZE, 0);
+ pBS->CopyMem(WriteCmd.data, NvBIOSflags, sizeof(PERSISTENT_BIOS_TPM_FLAGS));
+
+ Status = tcgSvc->PassThroughToTpm ( tcgSvc, \
+ sizeof(TPM_NV_WRITE_CMD_HDR) + NV_DATA_SIZE, \
+ (UINT8*)&WriteCmd, \
+ sizeof(TPM_NV_WRITE_RET), \
+ (UINT8*)&WriteRet );
+
+ RetCode = WriteRet.returnCode;
+
+ if ( EFI_ERROR(Status) || (WriteRet.returnCode != 0)){
+
+ TRACE((TRACE_ALWAYS, "(TPM Error) Status: %r; RetCode: %x.\n", \
+ Status, \
+ TPM_H2NL(WriteRet.returnCode)));
+//wait for proper return codes
+ while(TPM_H2NL(RetCode)==INTERNAL_TPM_DOING_SELFTEST){
+
+ pBS->Stall (500000); //stall 500ms for Selftest to complete
+
+ Status = tcgSvc->PassThroughToTpm ( tcgSvc, \
+ sizeof(TPM_NV_WRITE_CMD_HDR) + NV_DATA_SIZE, \
+ (UINT8*)&WriteCmd, \
+ sizeof(TPM_NV_WRITE_RET), \
+ (UINT8*)&WriteRet );
+
+ RetCode = WriteRet.returnCode;
+ if(Count == 0)break;
+ Count-=1; //total timeout is 5minutes for define the space
+ }
+
+ }
+
+
+ TpmDevice->Close( TpmDevice );
+
+
+ if(RetCode != 0)
+ {
+ return EFI_ACCESS_DENIED;
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmSet_Persistent_Bios_TPM_Flags
+//
+// Description: Sets persistent bios flags in TPM NV
+//
+//
+// Input: IN PERSISTENT_BIOS_TPM_FLAGS *
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS TcmSet_Persistent_Bios_TPM_Flags(PERSISTENT_BIOS_TPM_FLAGS *NvBIOSflags)
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmRead_Persistent_Bios_TPM_Flags
+//
+// Description: Sets persistent bios flags in TPM NV
+//
+//
+// Input: IN PERSISTENT_BIOS_TPM_FLAGS *
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS TcmRead_Persistent_Bios_TPM_Flags(PERSISTENT_BIOS_TPM_FLAGS *NvBIOSflags)
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: Read_Persistent_Bios_TPM_Flags
+//
+// Description: Read persistent bios flags in TPM NV
+//
+//
+// Input: IN PERSISTENT_BIOS_TPM_FLAGS *
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS Read_Persistent_Bios_TPM_Flags( PERSISTENT_BIOS_TPM_FLAGS *NvBIOSflags)
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ TPM_NV_READ_CMD ReadCmd;
+ TPM_NV_READ_RET ReadRet;
+ EFI_TCG_PROTOCOL *tcgSvc;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+ EFI_GUID FlagsStatusguid = AMI_TCG_CONFIRMATION_FLAGS_GUID;
+ PERSISTENT_BIOS_TPM_FLAGS TpmNvflags;
+ UINTN Size = sizeof(PERSISTENT_BIOS_TPM_FLAGS);
+
+ if(NvBIOSflags == NULL)return EFI_INVALID_PARAMETER;
+
+ Status = pBS->LocateProtocol( &gEfiTpmDxeDeviceProtocolGuid,NULL, &TpmDevice);
+ if ( EFI_ERROR( Status ))
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ Status = pBS->LocateProtocol( &gEfiTcgProtocolGuid, NULL, &tcgSvc );
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS, "Error: failed to locate TCG protocol: %r\n"));
+ return EFI_NOT_FOUND;
+ }
+
+ TpmDevice->Init( TpmDevice );
+
+ //read space
+ ReadCmd.dataSize = TPM_H2NL( NV_DATA_SIZE );
+ ReadCmd.tag = TPM_H2NS(TPM_TAG_RQU_COMMAND);
+ ReadCmd.paramSize = TPM_H2NL( sizeof(TPM_NV_READ_CMD));
+ ReadCmd.ordinal = TPM_H2NL(TPM_ORD_NV_ReadValue);
+ ReadCmd.nvIndex = TPM_H2NL(0x50010000);
+ ReadCmd.offset = TPM_H2NL(0x00000000);
+
+ Status = tcgSvc->PassThroughToTpm ( tcgSvc, \
+ sizeof(TPM_NV_READ_CMD) , \
+ (UINT8*)&ReadCmd, \
+ (sizeof(TPM_NV_READ_CMD) - 4 + NV_DATA_SIZE), \
+ (UINT8*)&ReadRet );
+
+ if ( EFI_ERROR(Status) || (ReadRet.returnCode != 0))
+ TRACE((TRACE_ALWAYS, "(TPM Error) Status: %r; RetCode: %x.\n", \
+ Status, \
+ TPM_H2NL(ReadRet.returnCode)));
+
+
+
+ TpmDevice->Close( TpmDevice );
+
+ if( TPM_H2NL(ReadRet.returnCode) == INTERNAL_TPM_BADINDEX ){
+
+ Status = pRS->GetVariable( L"TPMPERBIOSFLAGS", \
+ &FlagsStatusguid, \
+ NULL, \
+ &Size, \
+ &TpmNvflags );
+
+ if(!EFI_ERROR(Status)){
+ NvBIOSflags->NoPpiProvision = TRUE;
+ NvBIOSflags->NoPpiClear = FALSE;
+ NvBIOSflags->NoPpiMaintenance = FALSE;
+ return EFI_SUCCESS;
+ }else{
+ if(Internal_flag == 1)
+ {
+ return EFI_NOT_AVAILABLE_YET;
+ }
+ }
+ }
+
+ if( ReadRet.returnCode != 0)
+ {
+ //all ways require confirmation
+ NvBIOSflags->NoPpiProvision = TRUE;
+ NvBIOSflags->NoPpiClear = FALSE;
+ NvBIOSflags->NoPpiMaintenance = FALSE;
+ return EFI_SUCCESS;
+ }
+
+ pBS->CopyMem (NvBIOSflags, ReadRet.data, sizeof(PERSISTENT_BIOS_TPM_FLAGS));
+ return EFI_SUCCESS;
+}
+
+
+
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: NvSendTpmCommand
+//
+// Description: Sends a command to the TPM
+//
+// Input: *EFI_TCG_PROTOCOL - Tcg Protocol type.
+// UINT32 - Tcg Command ordinal.
+// int - cmd datasize.
+// VOID* - cmd data.
+//
+// Output: UINT32 - TPM_RESULT
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+UINT32
+NvSendTpmCommand (
+ IN EFI_TCG_PROTOCOL *tcg,
+ IN UINT32 ord,
+ IN int dataSize,
+ IN VOID *data
+)
+{
+ EFI_STATUS Status;
+ static UINT8 result[0x400];
+ TPM_1_2_RET_HEADER* tpmResult;
+ struct {
+ TPM_1_2_CMD_HEADER hdr;
+ UINT8 data[0x100];
+ } cmd;
+
+ cmd.hdr.Tag = TPM_H2NS (TPM_TAG_RQU_COMMAND);
+ cmd.hdr.ParamSize = TPM_H2NL (sizeof(TPM_1_2_RET_HEADER) + dataSize);
+ cmd.hdr.Ordinal = TPM_H2NL (ord);
+ pBS->CopyMem(cmd.data, data, dataSize);
+ Status = tcg->PassThroughToTpm ( tcg, \
+ sizeof(TPM_1_2_CMD_HEADER) + dataSize, \
+ (UINT8*)&cmd, \
+ sizeof (result), \
+ (UINT8*)&result );
+ tpmResult = (TPM_1_2_RET_HEADER*)result;
+ if ( EFI_ERROR(Status) || (tpmResult->RetCode != 0))
+ TRACE((TRACE_ALWAYS, "TXT (TPM Error) Status: %r; RetCode: %x.\n", \
+ Status, \
+ TPM_H2NL(tpmResult->RetCode) ));
+ return tpmResult->RetCode;
+}
+
+
+
+PERSISTENT_BIOS_TPM_MANAGEMENT_FLAGS_PROTOCOL PersistentBiosflagsManagementProtocol = {
+ Read_Persistent_Bios_TPM_Flags,
+ Set_Persistent_Bios_TPM_Flags
+};
+
+PERSISTENT_BIOS_TPM_MANAGEMENT_FLAGS_PROTOCOL TcmPersistentBiosflagsManagementProtocol = {
+ TcmRead_Persistent_Bios_TPM_Flags,
+ TcmSet_Persistent_Bios_TPM_Flags
+};
+
+EFI_GUID Overrideguid = AMI_BIOSPPI_FLAGS_MANAGEMENT_GUID;
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: AmiTcgPpiNvflagEntry
+//
+// Description: Entry point
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI AmiTcgPpiNvflagEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ EFI_TCG_PROTOCOL *tcgSvc;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+ PERSISTENT_BIOS_TPM_FLAGS NvBIOSflags;
+ TPM_RESULT RetCode;
+ UINTN Count = 10;
+ EFI_GUID FlagsStatusguid = AMI_TCG_CONFIRMATION_FLAGS_GUID;
+ UINTN Size = sizeof(PERSISTENT_BIOS_TPM_FLAGS);
+ TPM_DEF_NV_DATA CmdDefineNvram [] = { \
+ // TPM_NV_DATA_PUBLIC1 & TPM_NV_DATA_PUBLIC1.TPM_PCR_INFO_SHORT
+ TPM_H2NS(0x18), TPM_H2NL(0x50010000), TPM_H2NS(0x03), 0, 0, 0 , 0x1f, \
+ // TPM_NV_DATA_PUBLIC1.TPM_PCR_INFO_SHORT.TCPA_DIGEST
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ // TPM_NV_DATA_PUBLIC2.TPM_PCR_INFO_SHORT
+ TPM_H2NS(0x3), 0, 0, 0 , 0x1f, \
+ // TPM_NV_DATA_PUBLIC2.TPM_PCR_INFO_SHORT.TCPA_DIGEST
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ // TPM_NV_DATA_PUBLIC2
+ TPM_H2NS(0x17), TPM_H2NL(0x00000001), 0, 0, 0, TPM_H2NL(NV_DATA_SIZE), \
+ // TCPA_DIGEST
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ InitAmiLib( ImageHandle, SystemTable );
+
+ Status = pBS->LocateProtocol( &gEfiTpmDxeDeviceProtocolGuid,NULL, &TpmDevice);
+ if ( EFI_ERROR( Status ))
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ Status = pBS->LocateProtocol( &gEfiTcgProtocolGuid, NULL, &tcgSvc );
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS, "Error: failed to locate TCG protocol: %r\n"));
+ return EFI_NOT_FOUND;
+ }
+
+ if(AutoSupportType()){
+
+ Status = pBS->InstallProtocolInterface(
+ &ImageHandle,
+ &Overrideguid,
+ EFI_NATIVE_INTERFACE,
+ &TcmPersistentBiosflagsManagementProtocol);
+
+ return Status;
+ }
+
+ Internal_flag = 1;
+
+ Status = Read_Persistent_Bios_TPM_Flags(&NvBIOSflags);
+
+ TpmDevice->Init( TpmDevice );
+
+
+ //analyze return code
+ if(Status == EFI_NOT_AVAILABLE_YET){
+ //it might not be defined so define it
+
+ SendSelfTest(); //make sure we send selftest before defining space
+
+ RetCode = NvSendTpmCommand ( tcgSvc, \
+ TPM_ORD_NV_DefineSpace, \
+ sizeof(TPM_DEF_NV_DATA), \
+ &CmdDefineNvram );
+
+ if(RetCode != 0){
+ while(TPM_H2NL(RetCode) == INTERNAL_TPM_DOING_SELFTEST){
+
+ pBS->Stall (500000); //stall 500ms for Selftest to complete
+
+ RetCode = NvSendTpmCommand ( tcgSvc, \
+ TPM_ORD_NV_DefineSpace, \
+ sizeof(TPM_DEF_NV_DATA), \
+ &CmdDefineNvram );
+
+ if(Count == 0)break;
+ Count-=1;
+ }
+ }
+
+ Internal_flag = 0;
+
+ //read again to make sure we can read TPM Indices
+ Status = Read_Persistent_Bios_TPM_Flags(&NvBIOSflags);
+ if(Status)return EFI_ABORTED;
+
+ //if read is successful set the default values only once
+ //we only do this here because of the protections on TPM Nvram
+ //writes without owner. Do this only after defining the index
+ NvBIOSflags.NoPpiProvision = NO_PPI_PROVISION_DEFAULT;
+ NvBIOSflags.NoPpiClear = NO_PPI_CLEAR_DEFAULT;
+ NvBIOSflags.NoPpiMaintenance = NO_PPI_MAINTENANCE_DEFAULT;
+
+ Set_Persistent_Bios_TPM_Flags(&NvBIOSflags);
+ }
+ else if(Status){
+ return EFI_ABORTED;
+ }else{
+ //already allocated but check for first boot.
+ Status = pRS->GetVariable( L"TPMPERBIOSFLAGS", \
+ &FlagsStatusguid, \
+ NULL, \
+ &Size, \
+ &NvBIOSflags );
+
+ if(Status == EFI_NOT_FOUND){
+ NvBIOSflags.NoPpiProvision = NO_PPI_PROVISION_DEFAULT;
+ NvBIOSflags.NoPpiClear = NO_PPI_CLEAR_DEFAULT;
+ NvBIOSflags.NoPpiMaintenance = NO_PPI_MAINTENANCE_DEFAULT;
+ Set_Persistent_Bios_TPM_Flags(&NvBIOSflags);
+ }
+ }
+
+ TpmDevice->Close( TpmDevice );
+
+ Status = pBS->InstallProtocolInterface(
+ &ImageHandle,
+ &Overrideguid,
+ EFI_NATIVE_INTERFACE,
+ &PersistentBiosflagsManagementProtocol);
+
+ return Status;
+}
+
+
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/AmiTcgNvflagSample.cif b/Core/EM/TCG2/Common/AmiTcgNvflagSample.cif
new file mode 100644
index 0000000..ce3e997
--- /dev/null
+++ b/Core/EM/TCG2/Common/AmiTcgNvflagSample.cif
@@ -0,0 +1,12 @@
+<component>
+ name = "AmiTcgNvflagSample"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common"
+ RefName = "AmiTcgNvflagSample"
+[files]
+"AmiTcgNvflagSample.sdl"
+"AmiTcgNvflagSample.mak"
+"AmiTcgNvflagSample.c"
+"AmiTcgNvflagSample.dxs"
+"AmiTcgNvflagSample.h"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/AmiTcgNvflagSample.dxs b/Core/EM/TCG2/Common/AmiTcgNvflagSample.dxs
new file mode 100644
index 0000000..3e867b7
--- /dev/null
+++ b/Core/EM/TCG2/Common/AmiTcgNvflagSample.dxs
@@ -0,0 +1,44 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/AmiTcgNvflagSample/AmiTcgNvflagSample.dxs 1 4/21/14 2:17p Fredericko $Revision:
+//
+// $Date: 4/21/14 2:17p $Log:
+//
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: AmiTcgNvflagSample.dxs
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include "Include\Protocol\TcgService.h"
+
+DEPENDENCY_START
+ EFI_TCG_PROTOCOL_GUID
+DEPENDENCY_END
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//********************************************************************** \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/AmiTcgNvflagSample.h b/Core/EM/TCG2/Common/AmiTcgNvflagSample.h
new file mode 100644
index 0000000..3ba4ab1
--- /dev/null
+++ b/Core/EM/TCG2/Common/AmiTcgNvflagSample.h
@@ -0,0 +1,199 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/AmiTcgNvflagSample/AmiTcgNvflagSample.h 1 4/21/14 2:17p Fredericko $Revision:
+//
+// $Date:
+//*************************************************************************
+// Revision History
+// ----------------
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: AmiTcgNvflagSample
+//
+// Description: This is a sample file for support TCG Ppi. It creates and installed
+// a protocal to access the persistent bios tpm flags in Tpm NV 0x50010000.
+// See Ppi Spec 1.2
+//
+//<AMI_FHDR_END>
+//************************************************************************
+#include <AmiDxeLib.h>
+#include "token.h"
+#include "protocol\TcgService\TcgService.h"
+#include <Protocol\TpmDevice\TpmDevice.h>
+#include "TCGMisc.h"
+
+
+#pragma pack(1)
+
+typedef struct TPM_NV_READ_CMD
+{
+ TPM_TAG tag;
+ UINT32 paramSize;
+ TPM_COMMAND_CODE ordinal;
+ TPM_NV_INDEX nvIndex;
+ UINT32 offset;
+ UINT32 dataSize;
+} TPM_NV_READ_CMD;
+
+typedef struct TPM_NV_READ_RET
+{
+ TPM_TAG tag;
+ UINT32 paramSize;
+ TPM_RESULT returnCode;
+ UINT32 dataSize;
+ UINT8 data[NV_DATA_SIZE];
+ UINT8 nonceEven[20];
+ UINT8 nonceOdd[20];
+ BOOLEAN ContinueAuthSession;
+ UINT8 ownerAuth[20];
+} TPM_NV_READ_RET;
+
+typedef struct TPM_NV_WRITE_CMD_HDR
+{
+ TPM_TAG tag;
+ UINT32 paramSize;
+ TPM_COMMAND_CODE ordinal;
+ TPM_NV_INDEX nvIndex;
+ UINT32 offset;
+ UINT32 dataSize;
+} TPM_NV_WRITE_CMD_HDR;
+
+typedef struct TPM_NV_WRITE_CMD
+{
+ TPM_NV_WRITE_CMD_HDR writeHeader;
+ UINT8 data[NV_DATA_SIZE];
+} TPM_NV_WRITE_CMD;
+
+
+typedef struct TPM_NV_WRITE_RET
+{
+ TPM_TAG tag;
+ UINT32 paramSize;
+ TPM_RESULT returnCode;
+ UINT8 nonceEven[20];
+ UINT8 nonceOdd[20];
+ BOOLEAN ContinueAuthSession;
+ UINT8 ownerAuth[20];
+} TPM_NV_WRITE_RET;
+
+
+typedef struct _TCPA_DIGEST {
+ UINT8 digest[20];
+} TCPA_DIGEST;
+
+typedef struct _TPM_PCR_SELECTION {
+ UINT16 sizeOfSelect;
+ UINT8 pcrSelect[3];
+} NV_PCR_SELECTION;
+
+typedef struct _TPM_PCR_INFO_SHORT {
+ UINT16 sizeOfSelect;
+ UINT8 pcrSelect[3];
+ UINT8 localityAtRelease;
+ TCPA_DIGEST digestAtRelease;
+} NV_PCR_INFO_SHORT;
+
+typedef struct _TPM_NV_ATTRIBUTES {
+ UINT16 tag;
+ UINT32 attributes;
+} NV_ATTRIBUTES;
+
+typedef struct _TPM_NV_DATA_PUBLIC1 {
+ UINT16 Tag_;
+ UINT32 NvIndex;
+ NV_PCR_INFO_SHORT PcrInfoRead;
+} NV_DATA_PUBLIC1;
+
+typedef struct _TPM_NV_DATA_PUBLIC2 {
+ NV_PCR_INFO_SHORT PcrInfoWrite;
+ NV_ATTRIBUTES PerMission;
+ UINT8 bReadSTClear;
+ UINT8 bWriteSTClear;
+ UINT8 bWriteDefine;
+ UINT32 DataSize;
+} NV_DATA_PUBLIC2;
+
+typedef struct _TPM_DEF_NV_DATA {
+ NV_DATA_PUBLIC1 TpmDefineSpaceIn_pubinfo1;
+ NV_DATA_PUBLIC2 TpmDefineSpaceIn_pubinfo2;
+ TCPA_DIGEST TpmDefineSpaceIn_encAuth;
+} TPM_DEF_NV_DATA;
+
+
+typedef struct TPM_NV_PUBLIC_DATA
+{
+ UINT16 tag;
+ UINT32 Index;
+ UINT16 InfoReadsizeOfSelect;
+ UINT16 InfoReadpcrSelect;
+ UINT8 InfoReadlocalityAtRelease;
+ UINT8 InfoReaddigestAtRelease[20];
+ UINT16 InfoWritesizeOfSelect;
+ UINT16 InfoWritepcrSelect;
+ UINT8 InfoWritelocalityAtRelease;
+ UINT8 InfoWritedigestAtRelease[20];
+ UINT16 AttribTag;
+ UINT32 Attributes;
+ BOOLEAN bReadSTClear;
+ BOOLEAN bWriteSTClear;
+ BOOLEAN bWriteDefine;
+ UINT32 dataSize;
+}TPM_NV_PUBLIC_DATA;
+
+
+typedef struct TPM_NV_DEFINESPCE_CMD
+{
+ TPM_TAG tag;
+ UINT32 paramSize;
+ TPM_COMMAND_CODE ordinal;
+ TPM_NV_PUBLIC_DATA pubInfo;
+ UINT8 encAuth[20];
+} TPM_NV_DEFINESPCE_CMD;
+
+
+typedef struct TPM_NV_DEFINESPCE_RET
+{
+ TPM_TAG tag;
+ UINT32 paramSize;
+ TPM_RESULT returnCode;
+ UINT8 nonceEven[20];
+ UINT8 nonceOdd[20];
+ BOOLEAN ContinueAuthSession;
+ UINT8 ownerAuth[20];
+} TPM_NV_DEFINESPCE_RET;
+
+
+#define INTERNAL_TPM_BADINDEX 0x00000002
+#define INTERNAL_TPM_DOING_SELFTEST 0x00000802
+
+#pragma pack()
+
+#define EFI_MAX_BIT 0x80000000
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/AmiTcgNvflagSample.mak b/Core/EM/TCG2/Common/AmiTcgNvflagSample.mak
new file mode 100644
index 0000000..5141bcf
--- /dev/null
+++ b/Core/EM/TCG2/Common/AmiTcgNvflagSample.mak
@@ -0,0 +1,75 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+#*************************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Common/AmiTcgNvflagSample/AmiTcgNvflagSample.mak 1 4/21/14 2:17p Fredericko $Revision:
+#
+# $Date: 4/21/14 2:17p $Log:
+#
+#*************************************************************************
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: AmiTcgNvflagSample.mak
+#
+# Description:
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+all : AmiTcgNvflagSample
+
+#---------------------------------------------------------------------------
+# Making AmiTcgNvflagSample
+#---------------------------------------------------------------------------
+AmiTcgNvflagSample : $(BUILD_DIR)\AmiTcgNvflagSample.mak AmiTcgNvflagSamplebin
+
+$(BUILD_DIR)\AmiTcgNvflagSample.mak : $(AMI_TCG_NVFLAG_SAMPLE_DIR)\$(@B).cif $(AMI_TCG_NVFLAG_SAMPLE_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(AMI_TCG_NVFLAG_SAMPLE_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+MODULE_CFLAGS=$(CFLAGS)\
+ /I$(TCG_DIR)\
+ /I$(TPM12_DIR)\
+ /I$(TCG_DIR)\Common\
+ /I$(AMI_TCG_PLATFORM_DXE_DIR)\
+ /I$(TCG_DIR)\protocol\TcgService\
+ /I$(TCG_DIR)\protocol\TpmDevice\
+ /I$(PROJECT_DIR)\Include\Protocol\
+
+AmiTcgNvflagSample_OBJECTS = \
+$(BUILD_DIR)\$(AMI_TCG_NVFLAG_SAMPLE_DIR)\AmiTcgNvflagSample.obj \
+
+AmiTcgNvflagSamplebin: $(AMIDXELIB) $(BUILD_DIR)\AmiTcmlib.lib
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\AmiTcgNvflagSample.mak all\
+ "CFLAGS=$(MODULE_CFLAGS)"\
+ GUID=50F6096D-7C98-4c78-9A1D-C5A1833B6A88 \
+ ENTRY_POINT=AmiTcgPpiNvflagEntry \
+ TYPE=BS_DRIVER \
+ "OBJECTS=$(AmiTcgNvflagSample_OBJECTS)"\
+ DEPEX1_TYPE=EFI_SECTION_DXE_DEPEX \
+ COMPRESS=1
+#---------------------------------------------------------------------------
+
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
diff --git a/Core/EM/TCG2/Common/AmiTcgNvflagSample.sdl b/Core/EM/TCG2/Common/AmiTcgNvflagSample.sdl
new file mode 100644
index 0000000..13923e6
--- /dev/null
+++ b/Core/EM/TCG2/Common/AmiTcgNvflagSample.sdl
@@ -0,0 +1,66 @@
+TOKEN
+ Name = "AMI_TCG_NVFLAG_SAMPLE_SUPPORT"
+ Value = "1"
+ Help = "Sample module to provide interface to manipulate TPM NV BIOS FLAGS"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetH = Yes
+ TargetMAK = Yes
+ Master = Yes
+ Token = "USE_AMI_PERSISTENT_BIOS_MANAGEMENT_FLAGS_SUPPORT" "=" "1"
+ Token = "TCGPPISPEC_1_2_SUPPORT" "=" "1"
+ Token = "TPM12Enabled" "!=" "0"
+End
+
+
+TOKEN
+ Name = "NV_DATA_SIZE"
+ Value = "10"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "NO_PPI_PROVISION_DEFAULT"
+ Value = "001h"
+ Help = "default for TPM NoPpiProvision flag"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "NO_PPI_CLEAR_DEFAULT"
+ Value = "000h"
+ Help = "default for TPM NoPpiclear flag"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "NO_PPI_MAINTENANCE_DEFAULT"
+ Value = "000h"
+ Help = "default for TPM NoPpiclear flag"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+PATH
+ Name = "AMI_TCG_NVFLAG_SAMPLE_DIR"
+End
+
+MODULE
+ Help = "AmiTcgNvflagSample.mak"
+ File = "AmiTcgNvflagSample.mak"
+End
+
+
+ELINK
+ Name = "$(BUILD_DIR)\AmiTcgNvflagSample.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/Common.cif b/Core/EM/TCG2/Common/Common.cif
new file mode 100644
index 0000000..d79a439
--- /dev/null
+++ b/Core/EM/TCG2/Common/Common.cif
@@ -0,0 +1,21 @@
+<component>
+ name = "Common"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common"
+ RefName = "Common"
+[parts]
+"TcgPei"
+"TcgDxe"
+"AmiTcgBinaries"
+"AmiTcgNvflagSample"
+"AmiTcgPlatform"
+"TcgDxeplatform"
+"TcgLegacy"
+"TcgPeiplatform"
+"TcgPlatformSetupPeiPolicy"
+"TcgPlatformSetupPolicy"
+"TcgSetup"
+"TCGSmm"
+"TpmClearOnRollback"
+"Tpm20PlatformDxe"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/CommonHeaders.cif b/Core/EM/TCG2/Common/CommonHeaders.cif
new file mode 100644
index 0000000..324c25a
--- /dev/null
+++ b/Core/EM/TCG2/Common/CommonHeaders.cif
@@ -0,0 +1,19 @@
+<component>
+ name = "CommonHeaders"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common"
+ RefName = "CommonHeaders"
+[files]
+"TCGMisc.h"
+"TcgPrivate.h"
+"TcgPrivate.c"
+[parts]
+"TcgService_PPI"
+"TcgService_Protocol"
+"TpmDevice_PPI"
+"TpmDevice_Protocol"
+"AmiTcgPlatformProtocol"
+"AmiTpmClearOnRollbackProtocol"
+"Tpm20Includes"
+"AmiTcgPlatformPpi"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/EMpCallBin.asm b/Core/EM/TCG2/Common/EMpCallBin.asm
new file mode 100644
index 0000000..f63c3d7
--- /dev/null
+++ b/Core/EM/TCG2/Common/EMpCallBin.asm
@@ -0,0 +1,337 @@
+;**********************************************************************
+;**********************************************************************
+;** **
+;** (C)Copyright 1985-2005, American Megatrends, Inc. **
+;** **
+;** All Rights Reserved. **
+;** **
+;** 6145-F Northbelt Pkwy, Norcross, GA 30071 **
+;** **
+;** Phone: (770)-246-8600 **
+;** **
+;**********************************************************************
+;*************************************************************************
+; $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/EMpCallBin.asm 1 4/21/14 2:16p Fredericko $
+;
+; $Revision: 1 $
+;
+; $Date: 4/21/14 2:16p $
+;*************************************************************************
+; Revision History
+; ----------------
+; $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/EMpCallBin.asm $
+;
+; 1 4/21/14 2:16p Fredericko
+;
+; 1 10/08/13 12:03p Fredericko
+; Initial Check-In for Tpm-Next module
+;
+; 1 7/10/13 5:51p Fredericko
+; [TAG] EIP120969
+; [Category] New Feature
+; [Description] TCG (TPM20)
+;
+; 13 5/09/12 6:38p Fredericko
+; Fix for possible Tcm hang issues during reboot cycles.
+;
+; 12 1/20/12 9:13p Fredericko
+; Added code to work around RTC issue when using legacy IO support.
+;
+; 11 4/22/11 8:53p Fredericko
+; Token to enable stack workaround for binaries that don't return
+; properly.
+;
+; 10 3/29/11 1:13p Fredericko
+;
+; [TAG] EIP 54642
+; [Category] Improvement
+; [Description] 1. Checkin Files related to TCG function override
+; 2. Include TCM and TPM auto detection
+; [Files] Affects all TCG files
+;
+; 9 3/28/11 2:22p Fredericko
+; [TAG] EIP 54642
+; [Category] Improvement
+; [Description] 1. Checkin Files related to TCG function override
+; 2. Include TCM and TPM auto detection
+; [Files] Affects all TCG files
+;
+; 8 5/19/10 5:38p Fredericko
+; Included File Header
+; Included File Revision History
+; Updated AMI Function Headers
+; Code Beautification
+; EIP 37653
+;
+; 7 4/16/10 10:36a Fredericko
+; Function Headers updated
+;
+; 6 3/23/10 9:21p Fredericko
+;
+; 5 3/23/10 6:56p Fredericko
+;
+; 4 3/19/10 4:27p Fredericko
+; Modified the way Driver calls into legacy TCG Binary.
+;
+; 3 6/02/09 1:12p Fredericko
+;
+; 2 5/18/09 6:04p Fredericko
+;
+; 1 5/18/09 6:03p Fredericko
+; Initial check-in for EMpCallBin.asm for CTPM support infrastructure
+;**********************************************************************
+;<AMI_FHDR_START>
+;
+; Name: EMpCallBin.asm
+;
+; Description:
+; Contains functions for legacy TCG calls in 32 bit Binaries
+;
+;<AMI_FHDR_END>
+;**********************************************************************
+.code
+ INCLUDE token.equ
+
+;Global variable for MpLoc
+ public MpLoc
+ MpLoc label dword
+ FWORD ?
+
+public TPMRTCSave
+ TPMRTCSave label dword
+ WORD ?
+
+TPMTransmitEntryStruct STRUC
+ pbInBuf DD ? ;[IN] Pointer to input data for the data transfers to TPM
+ dwInLen DD ? ; [IN] Length of the input data record
+ pbOutBuf DD 0 ; [OUT] Pointer to output buffer for the data from the TPM
+ dwOutLen DD 0 ; [IN/OUT] DWORD to store the length info of the
+ ; output data record.
+TPMTransmitEntryStruct ENDS
+
+
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: Prepare2Thunkproc
+;
+; Description:
+; Function to setup location of Mp Driver as a local variable
+;
+; Input:
+; ecx - Location of MP Driver
+; dx - Segment for MP Driver
+;
+; Output:
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+Prepare2Thunkproc proc
+ push rax
+ push rcx
+ push rdx
+ mov dword ptr [MpLoc],ecx
+ mov word ptr [MpLoc + 4],dx
+ pop rdx
+ pop rcx
+ pop rax
+ ret
+Prepare2Thunkproc ENDP
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: TcgDxeCallMPDriver (TCM_support eq 0)
+;
+; Description:
+; Makes a function call into MP Driver
+;
+; Input:
+; rcx - Call type: 4-Buffer Transmission call
+; rsi - Buffer to be tansmitted
+;
+; Output:
+; rax - TCG return code
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+TpmDxeCallMPDriver proc
+ push rbp
+ push rax
+ push rcx
+ push rdx
+ mov rbp,rsp
+ cmp rcx, 04h
+ jnz Empty_Buff
+ MOV rsi, rdx
+Empty_Buff:
+ mov rax, rcx
+ push rcx
+ mov rcx, offset next
+IF MKF_Stack_Work_Around
+ mov dword ptr [IP_Offset], ecx
+ENDIF
+IF MKF_PMBASE_RTC_WKAround
+ push rax
+ push rdx
+ mov dx, MKF_PM_BASE_ADDRESS
+ in ax, dx
+ mov word ptr [TPMRTCSave],ax
+ pop rdx
+ pop rax
+ENDIF
+ pop rcx
+ call fword ptr [MpLoc]
+IF MKF_Stack_Work_Around
+ db 0eah
+IP_Offset:
+ dd 0
+ dw 038h
+ENDIF
+next:
+IF MKF_PMBASE_RTC_WKAround
+ push rax
+ push rdx
+ mov dx,MKF_PM_BASE_ADDRESS
+ in ax, dx
+ test ax, dx
+ jz RtcNotSet
+ mov ax, word ptr [TPMRTCSave]
+ and ax,0FBFEh
+ or ax,0400h
+ out dx, ax
+RtcNotSet:
+ pop rdx
+ pop rax
+ENDIF
+ mov rsp,rbp
+ pop rdx
+ pop rcx
+ pop rax
+ pop rbp
+ ret
+TpmDxeCallMPDriver ENDP
+
+
+
+TcmIoDelay proc
+ push rax
+ mov al, 80h
+ out 080h, al
+ in al, 080h
+ pop rax
+ ret
+TcmIoDelay ENDP
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: TcgDxeCallMPDriver (TCM_support eq 1)
+;
+; Description:
+; Makes a function call into MP Driver
+;
+; Input:
+; rcx - Call type: 4-Buffer Transmission call
+; rsi - Buffer to be tansmitted
+;
+; Output:
+; rax - TCG return code
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+TcmDxeCallMPDriver proc
+ push rax
+ push rcx
+ push rdx
+ push rsi
+ cmp rcx, 04h
+ jnz Empty_Buff
+ MOV rsi, rdx
+Empty_Buff:
+ mov rax, rcx
+ call TcmIoDelay
+ call fword ptr [MpLoc]
+ call TcmIoDelay
+ pop rsi
+ pop rdx
+ pop rcx
+ pop rax
+ ret
+TcmDxeCallMPDriver ENDP
+
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: TcgThunk32
+;
+; Description:
+; Go to compatibility mode for MP driver
+;
+; Input:
+;
+; Output:
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+TcgThunk32 proc
+TcgThunk32 ENDP
+
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: TcgThunkSwitchback
+;
+; Description:
+; Switch back to 64bit mode
+;
+; Input:
+;
+; Output:
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+TcgThunkSwitchback proc
+TcgThunkSwitchback ENDP
+
+END
diff --git a/Core/EM/TCG2/Common/EMpCallBin32.asm b/Core/EM/TCG2/Common/EMpCallBin32.asm
new file mode 100644
index 0000000..bc030eb
--- /dev/null
+++ b/Core/EM/TCG2/Common/EMpCallBin32.asm
@@ -0,0 +1,251 @@
+;**********************************************************************
+;**********************************************************************
+;** **
+;** (C)Copyright 1985-2005, American Megatrends, Inc. **
+;** **
+;** All Rights Reserved. **
+;** **
+;** 6145-F Northbelt Pkwy, Norcross, GA 30071 **
+;** **
+;** Phone: (770)-246-8600 **
+;** **
+;**********************************************************************
+;**********************************************************************
+; $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/EMpCallBin32.asm 1 4/21/14 2:16p Fredericko $
+;
+; $Revision: 1 $
+;
+; $Date: 4/21/14 2:16p $
+;*************************************************************************
+;Revision History
+; ----------------
+; $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/EMpCallBin32.asm $
+;
+; 1 4/21/14 2:16p Fredericko
+;
+; 1 10/08/13 12:03p Fredericko
+; Initial Check-In for Tpm-Next module
+;
+; 1 7/10/13 5:51p Fredericko
+; [TAG] EIP120969
+; [Category] New Feature
+; [Description] TCG (TPM20)
+;
+; 4 4/27/11 3:03p Fredericko
+; Changes for working around stack problems when calling into binaries
+; that don't return properly.
+;
+; 3 3/29/11 1:15p Fredericko
+;
+; [TAG] EIP 54642
+; [Category] Improvement
+; [Description] 1. Checkin Files related to TCG function override
+; 2. Include TCM and TPM auto detection
+; [Files] Affects all TCG files
+;
+;
+;**********************************************************************
+;<AMI_FHDR_START>
+;
+; Name: EMpCallBin32.asm
+;
+; Description:
+;
+;
+;<AMI_FHDR_END>
+;**********************************************************************
+.686
+.model flat
+.code
+ INCLUDE token.equ
+
+;Global variable for MpLoc
+ public MpLoc
+ MpLoc label dword
+ FWORD ?
+
+TPMTransmitEntryStruct STRUC
+ pbInBuf DD ? ;[IN] Pointer to input data for the data transfers to TPM
+ dwInLen DD ? ; [IN] Length of the input data record
+ pbOutBuf DD 0 ; [OUT] Pointer to output buffer for the data from the TPM
+ dwOutLen DD 0 ; [IN/OUT] DWORD to store the length info of the
+ ; output data record.
+TPMTransmitEntryStruct ENDS
+
+
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: Prepare2Thunkproc
+;
+; Description:
+; Function to setup location of Mp Driver as a local variable
+;
+; Input:
+; ecx - Location of MP Driver
+; dx - Segment for MP Driver
+;
+; Output:
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+_Prepare2Thunkproc proc
+ push ebp
+ mov ebp, esp
+ pusha
+ mov ecx, dword ptr [ebp + 08h]
+ mov edx, dword ptr [ebp + 0ch]
+ mov dword ptr [MpLoc],ecx
+ mov word ptr [MpLoc + 4], dx
+ popa
+ pop ebp
+ ret
+_Prepare2Thunkproc ENDP
+
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: TcgDxeCallMPDriver (TCM_support eq 0)
+;
+; Description:
+; Makes a function call into MP Driver
+;
+; Input:
+; rcx - Call type: 4-Buffer Transmission call
+; rsi - Buffer to be tansmitted
+;
+; Output:
+; rax - TCG return code
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+_TpmDxeCallMPDriver proc
+ push ebp
+ mov ebp, esp
+ pusha
+ mov ecx, dword ptr [ebp + 08h]
+ cmp ecx, 04h
+ jnz Empty_Buff
+ mov esi, dword ptr [ebp + 0ch]
+Empty_Buff:
+ mov eax, ecx
+ call fword ptr [MpLoc]
+IF MKF_Stack_Work_Around
+ pop ebp ;balance the stack after call
+ENDIF
+ popa
+ pop ebp
+ ret
+_TpmDxeCallMPDriver ENDP
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: TcgDxeCallMPDriver (TCM_support eq 1)
+;
+; Description:
+; Makes a function call into MP Driver
+;
+; Input:
+; rcx - Call type: 4-Buffer Transmission call
+; rsi - Buffer to be tansmitted
+;
+; Output:
+; rax - TCG return code
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+_TcmDxeCallMPDriver proc
+ push ebp
+ mov ebp, esp
+ pusha
+ mov ecx, dword ptr [ebp + 08h]
+ cmp ecx, 04h
+ jnz Empty_Buff
+ mov esi, dword ptr [ebp + 0ch]
+Empty_Buff:
+ mov eax, ecx
+ call fword ptr [MpLoc]
+ popa
+ pop ebp
+ ret
+_TcmDxeCallMPDriver ENDP
+
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: TcgThunk32
+;
+; Description:
+; Go to compatibility mode for MP driver
+;
+; Input:
+;
+; Output:
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+_TcgThunk32 proc
+_TcgThunk32 ENDP
+
+
+
+
+
+;<AMI_PHDR_START>
+;-----------------------------------------------------------------------------
+;
+; Procedure: TcgThunkSwitchback
+;
+; Description:
+; Switch back to 64bit mode
+;
+; Input:
+;
+; Output:
+;
+; Modified:
+;
+; Referrals:
+;
+; Notes:
+;---------------------------------------------------------------------------
+;<AMI_PHDR_END>
+_TcgThunkSwitchback proc
+_TcgThunkSwitchback ENDP
+END
diff --git a/Core/EM/TCG2/Common/EMpTcmDxe.c b/Core/EM/TCG2/Common/EMpTcmDxe.c
new file mode 100644
index 0000000..c06b7d2
--- /dev/null
+++ b/Core/EM/TCG2/Common/EMpTcmDxe.c
@@ -0,0 +1,482 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/EMpTcmDxe.c 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/EMpTcmDxe.c $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 2 3/11/14 6:39p Fredericko
+// [TAG] EIP151925
+// [Category] New Feature
+// [Description] Changes for TcgGeneric Regression Testing
+//
+// 1 10/08/13 12:03p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 4 5/09/12 6:40p Fredericko
+// Changes to streamline Tcm driver. Also fixes possible Tcm hang issues
+// during reboot cycles.
+//
+// 3 4/01/11 11:14a Fredericko
+//
+// 2 3/29/11 1:16p Fredericko
+//
+// 1 3/28/11 2:23p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 11 5/20/10 12:02p Fredericko
+// variable name change
+//
+// 7 3/25/10 7:18p Fredericko
+// changes for clearing of PPI variables on legacy or TCM support.
+//
+// 6 3/23/10 9:21p Fredericko
+//
+// 5 3/23/10 6:59p Fredericko
+// Changes for optimization issues with compiler.
+//
+// 4 3/19/10 4:29p Fredericko
+// Modified for legacy IO interface support
+//
+// 3 6/02/09 2:38p Fredericko
+//
+// 2 6/02/09 1:12p Fredericko
+//
+// 1 5/18/09 6:06p Fredericko
+// Initial check-in for EMpTpmDxe.c for CTPM support infrastructure.
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: EMpTpmDxe.c
+//
+// Description:
+// Contains function that help with making legacy TCG calls
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include "TcgTpm12.h"
+#include <TpmLib.h>
+#include "Protocol\TpmDevice\TpmDevice.h"
+#include <AmiDxeLib.h>
+#include "TcgMisc.h"
+#include "token.h"
+#include "Efi.h"
+
+#define _CR( Record, TYPE,\
+ Field )((TYPE*) ((CHAR8*) (Record)- (CHAR8*) &(((TYPE*) 0)->Field)))
+
+#define TPM_DXE_PRIVATE_DATA_FROM_THIS( this )\
+ _CR( this, TPM_DXE_PRIVATE_DATA, TpmInterface )
+
+typedef struct _TPM_DXE_PRIVATE_DATA
+{
+ EFI_TPM_DEVICE_PROTOCOL TpmInterface;
+} TPM_DXE_PRIVATE_DATA;
+
+static UINTN FuncID;
+static TPMTransmitEntryStruct EmptyBuf;
+static UINT32 Ret;
+UINT8 *SHA_ARRAY;
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: EMpTcmDxeInit
+//
+// Description: Call to OEM driver to initialize TPM.
+//
+// Input: IN EFI_TPM_DEVICE_PROTOCOL *This
+//
+// Returns: EFI_STATUS
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI EMpTcmDxeInit(
+ IN EFI_TPM_DEVICE_PROTOCOL *This )
+{
+ TPM_DXE_PRIVATE_DATA *Private;
+ EFI_PHYSICAL_ADDRESS TPM_Base = (EFI_PHYSICAL_ADDRESS)PORT_TPM_IOMEMBASE;
+
+ FuncID = MA_FUNCTION_INIT;
+ Private = TPM_DXE_PRIVATE_DATA_FROM_THIS( This );
+ TcmDxeCallMPDriver( FuncID, &EmptyBuf, &Ret );
+
+ if ( !Ret )
+ {
+ return EFI_SUCCESS;
+ }
+ return EFI_DEVICE_ERROR;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: EMpTcmDxeClose
+//
+// Description: Close TPM connection for locality 0
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+///
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI EMpTcmDxeClose(
+ IN EFI_TPM_DEVICE_PROTOCOL *This )
+{
+ TPM_DXE_PRIVATE_DATA *Private;
+
+ FuncID = MP_FUNCTION_CLOSE;
+ Private = TPM_DXE_PRIVATE_DATA_FROM_THIS( This );
+ TcmDxeCallMPDriver( FuncID, &EmptyBuf, &Ret );
+
+ if ( !Ret )
+ {
+ return EFI_SUCCESS;
+ }
+ return EFI_DEVICE_ERROR;
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+//
+// Name: EMpTcmDxeGetStatusInfo
+//
+// Description: GetStatus Info from MP driver
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI EMpTcmDxeGetStatusInfo(
+ IN EFI_TPM_DEVICE_PROTOCOL * This
+ )
+{
+ TPM_DXE_PRIVATE_DATA *Private;
+
+ FuncID = MP_FUNCTION_GET_STATUS;
+ Private = TPM_DXE_PRIVATE_DATA_FROM_THIS( This );
+ TcmDxeCallMPDriver( FuncID, &EmptyBuf, &Ret );
+
+ if ( !Ret )
+ {
+ return EFI_SUCCESS;
+ }
+ return EFI_DEVICE_ERROR;
+}
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+//
+// Name: EMpTcmDxeGetStatusInfo
+//
+// Description: GetStatus Info from MP driver
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+BOOLEAN
+EFIAPI EMpTcmDxeSHA1Setup (
+IN EFI_TPM_DEVICE_PROTOCOL *This,
+IN UINTN NoInBuffers,
+IN TPM_TRANSMIT_BUFFER *InBuffers,
+IN OUT void **Buffer
+)
+{
+
+ TPM_1_2_CMD_HEADER *SHA1HeaderCheck;
+
+ SHA1HeaderCheck = (TPM_1_2_CMD_HEADER*)InBuffers->Buffer;
+
+ if ( SHA1HeaderCheck->Ordinal !=TPM_H2NL(TCM_ORD_SHA1CompleteExtend ) &&
+ SHA1HeaderCheck->Ordinal !=TPM_H2NL( TCM_ORD_SHA1Update ))
+ {
+ //no need to modify buffers just pass it through
+ return FALSE;
+ }
+
+ //if we get here it means the buffer needs to be modified!
+ pBS->AllocatePool( EfiBootservicesData,
+ InBuffers[0].Size + InBuffers[1].Size,
+ &SHA_ARRAY );
+
+ pBS->CopyMem( &SHA_ARRAY[0],
+ InBuffers[0].Buffer,
+ InBuffers[0].Size );
+
+ pBS->CopyMem( &SHA_ARRAY[InBuffers[0].Size],
+ InBuffers[1].Buffer,
+ InBuffers[1].Size );
+ *Buffer = SHA_ARRAY;
+ return TRUE;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+//
+// Name: EMpTcmDxeTransmit
+//
+// Description: Dxe Transmit Tcg Data
+//
+// Input: IN EFI_TPM_DEVICE_PROTOCOL *This,
+// IN UINTN NoInBuffers,
+// IN TPM_TRANSMIT_BUFFER *InBuffers,
+// IN UINTN NoOutBuffers,
+// IN OUT TPM_TRANSMIT_BUFFER *OutBuffers
+//
+// Output: EFI STATUS
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+
+EFI_STATUS
+EFIAPI EMpTcmDxeTransmit(
+ IN EFI_TPM_DEVICE_PROTOCOL *This,
+ IN UINTN NoInBuffers,
+ IN TPM_TRANSMIT_BUFFER *InBuffers,
+ IN UINTN NoOutBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutBuffers )
+{
+ TPM_DXE_PRIVATE_DATA *Private;
+ TPMTransmitEntryStruct FillESI;
+ UINTN FuncID = (UINTN)MP_FUNCTION_TRANSMIT;
+ UINT32 Ret;
+ UINT8 *SHA_ARRAY_OUT = NULL;
+ BOOLEAN FillBuff = FALSE;
+ BOOLEAN Other = FALSE;
+ UINTN i = 0, loc = 0;
+ UINT8 *Tpm_SHA_ARRAY= NULL;
+ EFI_STATUS Status;
+
+
+ if(NoInBuffers == 0 || InBuffers == NULL || NoOutBuffers == 0 || OutBuffers == NULL)
+ return EFI_INVALID_PARAMETER;
+
+ FillESI.dwInLen = 0;
+ FillESI.dwOutLen = 0;
+
+ for (; i < NoInBuffers; i++ )
+ {
+ FillESI.dwInLen += (UINT32)InBuffers[i].Size;
+ }
+
+ Status = pBS-> AllocatePool( EfiBootservicesData, FillESI.dwInLen, &Tpm_SHA_ARRAY);
+ if(EFI_ERROR(Status))return Status;
+
+ for (i = 0; i < NoOutBuffers; i++ )
+ {
+ FillESI.dwOutLen += (UINT32)OutBuffers[i].Size;
+ }
+
+ Status = pBS-> AllocatePool( EfiBootservicesData, FillESI.dwOutLen, &SHA_ARRAY_OUT );
+ if(EFI_ERROR(Status))return Status;
+
+
+ for (i = 0; i < NoInBuffers; i++ )
+ {
+ pBS->CopyMem(Tpm_SHA_ARRAY + loc,
+ InBuffers[i].Buffer,
+ InBuffers[i].Size );
+
+ loc += InBuffers[i].Size;
+ }
+
+ FillESI.pbInBuf = (UINT32)(EFI_PHYSICAL_ADDRESS) Tpm_SHA_ARRAY;
+ FillESI.pbOutBuf = (UINT32)(EFI_PHYSICAL_ADDRESS) SHA_ARRAY_OUT;
+
+ Private = TPM_DXE_PRIVATE_DATA_FROM_THIS( This );
+ TcmDxeCallMPDriver( FuncID, &FillESI, &Ret );
+
+ if ( Tpm_SHA_ARRAY != NULL )
+ {
+ pBS->FreePool( Tpm_SHA_ARRAY );
+ }
+
+ loc = 0;
+
+ for (i=0; i < NoOutBuffers; i++ )
+ {
+ pBS->CopyMem( OutBuffers[i].Buffer,
+ &SHA_ARRAY_OUT[loc],
+ OutBuffers[i].Size );
+ loc += (UINTN)OutBuffers[i].Size;
+ }
+
+ if ( SHA_ARRAY_OUT != NULL )
+ {
+ pBS->FreePool( SHA_ARRAY_OUT );
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+
+
+static TPM_DXE_PRIVATE_DATA mTpmPrivate = {
+ {
+ EMpTcmDxeInit,
+ EMpTcmDxeClose,
+ EMpTcmDxeGetStatusInfo,
+ EMpTcmDxeTransmit
+ }
+};
+
+
+EFI_GUID legTcgGuid = AMI_TCG_RESETVAR_HOB_GUID;
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+//
+// Name: TcmDxeEntry
+//
+// Description: TpmDxeEntry, Init TpmDxeDriver and install protocol
+//
+// Input: EFI_HANDLE ImageHandle
+// EFI_SYSTEM_TABLE *SystemTable
+//
+// Output: EFI STATUS
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+
+EFI_STATUS
+EFIAPI TcmDxeEntry(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable)
+{
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS TPM_Base = (EFI_PHYSICAL_ADDRESS)PORT_TPM_IOMEMBASE;
+ FAR32LOCALS *TempLoc = NULL;
+ EFI_GUID gMpDriverHobGuid = EFI_TCG_MPDriver_HOB_GUID;
+
+ TempLoc = (FAR32LOCALS*)LocateATcgHob( pST->NumberOfTableEntries,
+ pST->ConfigurationTable,
+ &gMpDriverHobGuid );
+
+
+ if(TempLoc->Offset == 0) return EFI_NOT_FOUND;
+
+ Prepare2Thunkproc( TempLoc->Offset, TempLoc->Selector );
+ Status = pBS->InstallMultipleProtocolInterfaces(
+ &ImageHandle,
+ &gEfiTpmDeviceProtocolGuid,
+ &mTpmPrivate.TpmInterface,
+ NULL
+ );
+
+ return Status;
+}
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/EMpTcmPei.c b/Core/EM/TCG2/Common/EMpTcmPei.c
new file mode 100644
index 0000000..480aa61
--- /dev/null
+++ b/Core/EM/TCG2/Common/EMpTcmPei.c
@@ -0,0 +1,691 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/EMpTcmPei.c 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/EMpTcmPei.c $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 8 5/09/12 6:13p Fredericko
+// Changes to streamline Tcm driver. Also fixes possible Tcm hang issues
+// during reboot cycles.
+//
+// 7 12/12/11 3:19p Fredericko
+// [TAG] EIP76865
+// [Category] Improvement
+// [Description] Dual Support for TCM and TPM. System could hang in TXT
+// if txt is enabled in setup
+// [Files] AmiTcgPlatfompeilib.c, AmiTcgPlatformPpi.cif,
+// AmiTcgPlatformPpi.h, AmiTcgPlatformProtocol.cif,
+// AmiTcgPlatformProtocol.h,
+// EMpTcmPei.c, TcgDxe.cif, TcgPei.cif, TcgPeiAfterMem.cif,
+// TcgPeiAfterMem.mak, TcgTcmPeiAfterMem.c, xTcgDxe.c, xTcgPei.c,
+// xTcgPeiAfterMem.c
+//
+// 6 4/18/11 2:26p Fredericko
+//
+// 5 4/14/11 6:17p Fredericko
+// Disable optimization for asm related changes.
+//
+// 4 4/06/11 12:23p Fredericko
+//
+// 3 4/01/11 9:33a Fredericko
+// Updated function Header
+//
+// 2 3/29/11 12:58p Fredericko
+//
+// 1 3/28/11 2:14p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 8 5/19/10 5:54p Fredericko
+// Updated AMI copyright header
+// Included File Header
+// Code Beautification
+// EIP 37653
+//
+// 7 4/08/10 6:45p Fredericko
+// removed Verify_TCG_VARIABLES, now called in xtcgpei.c
+//
+// 6 3/26/10 12:51a Fredericko
+//
+// 5 3/19/10 5:14p Fredericko
+// modified for legacy IO interface support
+//
+// 4 6/02/09 1:16p Fredericko
+//
+// 3 6/01/09 4:29p Fredericko
+//
+// 2 5/18/09 5:50p Fredericko
+//
+// 1. Initial check-in for EMpTpmPei.c for CTPM support infrastructure.
+//**********************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: EMpTpmPei.c
+//
+// Description:
+// Handles legacy calls into 32bit Binaries
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include <Pei.h>
+#include <TcgTpm12.h>
+#include <TpmLib.h>
+#include <AmiPeiLib.h>
+#include "TcgMisc.h"
+#include "token.h"
+#include "TcgCommon.h"
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+
+
+#define _CR( Record, TYPE,\
+ Field )((TYPE*) ((CHAR8*) (Record)- (CHAR8*) &(((TYPE*) 0)->Field)))
+
+#define TPM_PEI_PRIVATE_DATA_FROM_THIS( This ) \
+ _CR( This, TPM_PEI_PRIVATE_DATA, TpmPpi )
+
+typedef struct _TPM_PEI_PRIVATE_DATA
+{
+ PEI_TPM_PPI TpmPpi;
+} TPM_PEI_PRIVATE_DATA;
+
+EFI_GUID gTcmCallbackguid = AMI_TCM_CALLBACK_GUID;
+EFI_GUID guid = EFI_TCG_MPDriver_HOB_GUID;
+
+typedef struct _TCM_PEI_CALLBACK
+{
+ EFI_PEI_NOTIFY_DESCRIPTOR NotifyDesc;
+ EFI_FFS_FILE_HEADER *FfsHeader;
+
+} TCM_PEI_CALLBACK;
+
+
+VOID TcmPeiCallMPDriver (
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 CFuncID,
+ TPMTransmitEntryStruct *CData,
+ UINT32* OUT CRetVal );
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTcmPeiInit
+//
+// Description: Call to OEM driver to initialize TCM
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI EMpTcmPeiInit(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI EMpTcmPeiInit2(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_NOT_AVAILABLE_YET;
+}
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTcmPeiClose
+//
+// Description: Call to OEM driver to Close TCM
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI EMpTcmPeiClose(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI EMpTcmPeiClose2(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_NOT_AVAILABLE_YET;
+}
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTcmPeiGetStatusInfo
+//
+// Description: Function call to get status infomation
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI_UNSUPPORTED
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI EMpTcmPeiGetStatusInfo(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTcmPeiSHA1Setup
+//
+// Description: Helper function to help with Command transmission to TCM
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+// IN UINTN NoInputBuffers
+// IN TPM_TRANSMIT_BUFFER *InputBuffers
+// IN OUT void **Buffer
+// IN UINT8 *SHA_ARRAY
+//
+// Output: BOOLEAN
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+BOOLEAN
+EFIAPI EMpTcmPeiSHA1Setup(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN OUT void **Buffer,
+ IN UINT8 *SHA_ARRAY )
+{
+ TPM_1_2_CMD_HEADER *SHA1HeaderCheck;
+ void *Context = NULL;
+
+
+ //check if this an SHA1 update or Complete call and set the buffer
+ //else no need to update the buffer is the same
+ SHA1HeaderCheck = (TPM_1_2_CMD_HEADER*)InputBuffers->Buffer;
+
+ if ( SHA1HeaderCheck->Ordinal !=
+ TPM_H2NL(
+ TCM_ORD_SHA1CompleteExtend ) && SHA1HeaderCheck->Ordinal !=
+ TPM_H2NL( TCM_ORD_SHA1Update ))
+ {
+ //no need to modify buffers just pass it through
+ return FALSE;
+ }
+
+
+ TcgCommonCopyMem( Context,
+ SHA_ARRAY,
+ InputBuffers[0].Buffer,
+ InputBuffers[0].Size );
+
+ TcgCommonCopyMem( Context,
+ &SHA_ARRAY[InputBuffers[0].Size],
+ InputBuffers[1].Buffer,
+
+ InputBuffers[1].Size );
+
+ *Buffer = SHA_ARRAY;
+ return TRUE;
+}
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTcmPeiTransmit
+//
+// Description: TCM Transmit function
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices,
+// IN UINTN NoInputBuffers,
+// IN TPM_TRANSMIT_BUFFER *InputBuffers,
+// IN UINTN NoOutputBuffers,
+// IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI EMpTcmPeiTransmit(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers )
+{
+ TPM_PEI_PRIVATE_DATA *Private;
+ TPMTransmitEntryStruct FillESI;
+ UINT8 FuncID = MP_FUNCTION_TRANSMIT;
+ UINT32 Ret;
+ void *buffer;
+ UINT8 SHA_ARRAY[INTERNAL_SHA_ARRAY_LENGTH];
+ UINT8 SHA_ARRAY_OUT[INTERNAL_SHA_ARRAY_LENGTH];
+ BOOLEAN FillBuff = FALSE;
+ TPM_1_2_CMD_HEADER *SHA1HeaderCheck;
+ void *Context = NULL;
+ UINT8 i = 0;
+ UINT8 loc = 0;
+
+ if ( !EMpTcmPeiSHA1Setup( This, PeiServices, NoInputBuffers, InputBuffers,
+ &buffer, SHA_ARRAY ))
+ {
+ FillESI.pbInBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)InputBuffers->Buffer;
+ FillESI.dwInLen = (UINT32)InputBuffers->Size;
+ FillESI.pbOutBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)OutputBuffers->Buffer;
+ FillESI.dwOutLen = (UINT32)OutputBuffers->Size;
+ }
+ else {
+ FillESI.pbInBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)SHA_ARRAY;
+ FillESI.dwInLen = 0;
+
+ for (; i < NoInputBuffers; i++ )
+ {
+ FillESI.dwInLen += (UINT32)InputBuffers[i].Size;
+ }
+
+ SHA1HeaderCheck = (TPM_1_2_CMD_HEADER*)InputBuffers->Buffer;
+
+ if ( SHA1HeaderCheck->Ordinal == TPM_H2NL( TCM_ORD_SHA1CompleteExtend ))
+ {
+ FillBuff = TRUE;
+ FillESI.pbOutBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)SHA_ARRAY_OUT;
+ FillESI.dwOutLen = (OutputBuffers[0].Size + OutputBuffers[1].Size
+ + OutputBuffers[2].Size);
+ }
+
+ if ( !FillBuff )
+ {
+ FillESI.pbOutBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)OutputBuffers->Buffer;
+ FillESI.dwOutLen = (UINT32)OutputBuffers->Size;
+ }
+ }
+
+ Private = TPM_PEI_PRIVATE_DATA_FROM_THIS( This );
+ TcmPeiCallMPDriver( PeiServices, FuncID, &FillESI, &Ret );
+
+ if ( FillBuff ) //setup output buffer for the interface
+ {
+ i = 0;
+ for (; i < NoOutputBuffers; i++ )
+ {
+ TcgCommonCopyMem( Context,
+ OutputBuffers[i].Buffer,
+ &SHA_ARRAY_OUT[loc],
+ OutputBuffers[i].Size );
+
+ loc += OutputBuffers[i].Size;
+ }
+
+ }
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI EMpTcmPeiTransmit2(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers )
+{
+ return EFI_NOT_AVAILABLE_YET;
+}
+
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmPeiCallMPDriver
+//
+// Description: Interface to performing MP driver function calls in PEI
+// Uses _ASM directives. Return Value in EAX return as status
+//
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+// IN UINT8 CFuncID,
+// IN TPMTransmitEntryStruct * CData,
+// OUT UINT32* CRetVal
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+VOID TcmPeiCallMPDriver(
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 CFuncID,
+ TPMTransmitEntryStruct * CData,
+ UINT32* OUT CRetVal )
+{
+ UINT32 ReturnVal;
+ FAR32LOCALS CommonLegX;
+ EFI_GUID guidMA = EFI_TCG_MADriver_HOB_GUID;
+ EFI_GUID guidMP = EFI_TCG_MPDriver_HOB_GUID;
+ TPMTransmitEntryStruct IntCData = *CData;
+ UINT32 Address = (UINT32)&IntCData;
+ FAR32LOCALS InternalMPLoc;
+
+
+ FillDriverLoc( &InternalMPLoc.Offset, PeiServices, &guid );
+
+ CommonLegX.Offset = 0;
+ CommonLegX.Selector = 0;
+ CommonLegX.Offset = InternalMPLoc.Offset;
+ CommonLegX.Selector = SEL_flatCS;
+
+ _asm {
+ xor eax, eax
+ mov al, [CFuncID]
+ cmp eax, MP_FUNCTION_TRANSMIT
+ jnz Empty_Buff
+ mov ESI, Address
+Empty_Buff:
+ call fword ptr [CommonLegX];
+ mov ReturnVal, eax
+ }
+ *CRetVal = ReturnVal;
+}
+
+
+static TPM_PEI_PRIVATE_DATA mTcmPrivate = {
+ {
+ EMpTcmPeiInit,
+ EMpTcmPeiClose,
+ EMpTcmPeiGetStatusInfo,
+ EMpTcmPeiTransmit
+ }
+};
+
+static TPM_PEI_PRIVATE_DATA mTcmPrivate2 = {
+ {
+ EMpTcmPeiInit2,
+ EMpTcmPeiClose2,
+ EMpTcmPeiGetStatusInfo,
+ EMpTcmPeiTransmit2
+ }
+};
+
+static EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTpmPpiGuid,
+ &mTcmPrivate.TpmPpi
+ }
+};
+
+static EFI_PEI_PPI_DESCRIPTOR mPpiList2[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTpmPpiGuid,
+ &mTcmPrivate2.TpmPpi
+ }
+};
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: InitTcmEntry
+//
+// Description: Entry point for TCM ppi initialization after memory is installed
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI InitTcmEntry(
+IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
+ IN VOID *Ppi)
+{
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS TPM_Base = (EFI_PHYSICAL_ADDRESS)PORT_TPM_IOMEMBASE;
+ FAR32LOCALS InternalMPLoc;
+ EFI_PEI_PPI_DESCRIPTOR *PpiDesc;
+ PEI_TCG_PPI *TcmPpi;
+
+ Status = IsTpmPresent((TPM_1_2_REGISTERS_PTR)( UINTN ) TPM_Base );
+ if(EFI_ERROR(Status))
+ {
+ return Status;
+ }
+
+ FillDriverLoc( &InternalMPLoc.Offset, PeiServices, &guid );
+ if ( InternalMPLoc.Offset == 0 )
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gPeiTpmPpiGuid,
+ 0,
+ &PpiDesc,
+ &TcmPpi);
+ if(EFI_ERROR(Status))
+ {
+ return Status;
+ }
+
+
+ Status = (*PeiServices)->ReInstallPpi( PeiServices, PpiDesc, &mPpiList[0] );
+ if ( EFI_ERROR( Status ))
+ {
+ return EFI_UNLOAD_IMAGE;
+ }
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gPeiTpmPpiGuid,
+ 0,
+ &PpiDesc,
+ &TcmPpi );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return EFI_UNLOAD_IMAGE;
+ }
+
+ return Status;
+}
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmPeiEntry
+//
+// Description: Entry for TcmPei Device when TCM_Support is enabled
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcmPeiEntry(
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ EFI_STATUS Status;
+ TCM_PEI_CALLBACK *TcmCallback;
+
+ Status = (**PeiServices).AllocatePool(
+ PeiServices,
+ sizeof (TCM_PEI_CALLBACK),
+ &TcmCallback);
+
+ if ( !EFI_ERROR( Status ))
+ {
+ TcmCallback->NotifyDesc.Flags
+ = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
+ TcmCallback->NotifyDesc.Guid = &gTcmCallbackguid;
+ TcmCallback->NotifyDesc.Notify = InitTcmEntry;
+ TcmCallback->FfsHeader = FfsHeader;
+
+ Status = (*PeiServices)->NotifyPpi( PeiServices,
+ &TcmCallback->NotifyDesc );
+ }
+
+ Status = (*PeiServices)->InstallPpi( PeiServices, &mPpiList2[0] );
+ if ( EFI_ERROR( Status ))
+ {
+ return EFI_UNLOAD_IMAGE;
+ }
+
+ return Status;
+}
+
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/PPI/TcgService/TcgService.c b/Core/EM/TCG2/Common/PPI/TcgService/TcgService.c
new file mode 100644
index 0000000..906d671
--- /dev/null
+++ b/Core/EM/TCG2/Common/PPI/TcgService/TcgService.c
@@ -0,0 +1,64 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Abstract:
+
+ GUID definition for PEI_TCG_PPI
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgService.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgService.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 5/19/10 6:48p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgService.c
+//
+// Description:
+// Defines TcgPpiguid
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+#include <Efi.h>
+#include <Pei.h>
+#include <Tpm12.h>
+
+#include EFI_PPI_DEFINITION( TcgService )
+
+EFI_GUID gPeiTcgPpiGuid = PEI_TCG_PPI_GUID;
+
+EFI_GUID_STRING( &gPeiTcgPpiGuid, "TcgService", "TCG Services PPI" );
diff --git a/Core/EM/TCG2/Common/PPI/TcgService/TcgService.h b/Core/EM/TCG2/Common/PPI/TcgService/TcgService.h
new file mode 100644
index 0000000..c621600
--- /dev/null
+++ b/Core/EM/TCG2/Common/PPI/TcgService/TcgService.h
@@ -0,0 +1,122 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Abstract:
+
+ TCG Service PPI
+
+ Only minimum subset of features is contained in this PPI definition
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgService.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgService.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 6 3/29/11 2:59p Fredericko
+//
+// 5 3/28/11 3:14p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 4 5/19/10 6:49p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgService.h
+//
+// Description:
+// Header file for TcgService.c
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+#ifndef _TCG_SERVICE_H_
+#define _TCG_SERVICE_H_
+
+#include <TcgEfiTpm.h>
+#include <TCGMisc.h>
+#include <token.h>
+
+struct _PEI_TCG_PPI;
+
+typedef struct _PEI_TCG_PPI PEI_TCG_PPI;
+
+
+#define PEI_TCG_PPI_GUID \
+ {0x177d39d2, 0x43b8, 0x40c8, 0x9a, 0xe1, 0x3c, 0x51, 0x98, 0xd6, 0x94, 0x1e}
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TCG_LOG_EVENT)(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCG_PCR_EVENT *Event,
+ OUT UINT32 *EventNum
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TCG_HASH_LOG_EXTEND_EVENT)(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN TCG_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TCG_PASS_THROUGH_TO_TPM)(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiSerivces,
+ IN UINT32 TpmInputParameterBlockSize,
+ IN UINT8 *TpmInputParameterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock
+ );
+
+typedef struct _PEI_TCG_PPI
+{
+ PEI_TCG_HASH_LOG_EXTEND_EVENT TCGHashLogExtendEvent;
+ PEI_TCG_LOG_EVENT TCGLogEvent;
+ PEI_TCG_PASS_THROUGH_TO_TPM TCGPassThroughToTpm;
+} PEI_TCG_PPI;
+
+extern EFI_GUID gPeiTcgPpiGuid;
+
+#endif
diff --git a/Core/EM/TCG2/Common/PPI/TcgService/TcgTcmService.c b/Core/EM/TCG2/Common/PPI/TcgService/TcgTcmService.c
new file mode 100644
index 0000000..51c6f4a
--- /dev/null
+++ b/Core/EM/TCG2/Common/PPI/TcgService/TcgTcmService.c
@@ -0,0 +1,73 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Abstract:
+
+ GUID definition for PEI_TCG_PPI
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgTcmService.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgTcmService.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 3/29/11 3:00p Fredericko
+//
+// 1 3/28/11 3:16p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 2 5/19/10 6:48p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgService.c
+//
+// Description:
+// Defines TcgPpiguid
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+#include <Efi.h>
+#include <Pei.h>
+#include <Tpm12.h>
+
+#include EFI_PPI_DEFINITION( TcgTcmService )
+
+EFI_GUID gPeiTcmPpiGuid = PEI_TCG_PPI_GUID;
+
+EFI_GUID_STRING( &gPeiTcgPpiGuid, "TcgTcmService", "TCM Services PPI" );
diff --git a/Core/EM/TCG2/Common/PPI/TcgService/TcgTcmService.h b/Core/EM/TCG2/Common/PPI/TcgService/TcgTcmService.h
new file mode 100644
index 0000000..3f6c973
--- /dev/null
+++ b/Core/EM/TCG2/Common/PPI/TcgService/TcgTcmService.h
@@ -0,0 +1,181 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Abstract:
+
+ TCG Service PPI
+
+ Only minimum subset of features is contained in this PPI definition
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgTcmService.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgTcmService.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 9/29/11 6:08p Davidd
+// [TAG] EIP71378
+// [Category] Improvement
+// [Description] Customer names in source files
+// [Files] TcgTcmService.h
+//
+// 2 3/29/11 3:00p Fredericko
+//
+// 1 3/28/11 3:15p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 4 5/19/10 6:49p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+/*
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Abstract:
+
+ TCM Service PPI
+
+ Only minimum subset of features is contained in this PPI definition
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgTcmService.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_PPI/TcgService/TcgTcmService.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 9/29/11 6:08p Davidd
+// [TAG] EIP71378
+// [Category] Improvement
+// [Description] Customer names in source files
+// [Files] TcgTcmService.h
+//
+// 2 3/29/11 3:00p Fredericko
+//
+// 1 3/28/11 3:15p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG file override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 4 5/19/10 6:49p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TCMService.h
+//
+// Description:
+// Header file for TCMService.c
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCG_TCM_SERVICE_H_
+#define _TCG_TCM_SERVICE_H_
+
+#include <TcgEfiTpm.h>
+#include <TcgMisc.h>
+#include <token.h>
+
+struct _PEI_TCM_PPI;
+typedef struct _PEI_TCM_PPI PEI_TCM_PPI;
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TCM_LOG_EVENT)(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCM_PCR_EVENT *Event,
+ OUT UINT32 *EventNum );
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TCM_HASH_LOG_EXTEND_EVENT)(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN TCM_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TCM_PASS_THROUGH_TO_TCM)(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiSerivces,
+ IN UINT32 TcmInputParameterBlockSize,
+ IN UINT8 *TcmInputParameterBlock,
+ IN UINT32 TcmOutputParameterBlockSize,
+ IN UINT8 *TcmOutputParameterBlock
+ );
+
+typedef struct _PEI_TCM_PPI
+{
+ PEI_TCM_HASH_LOG_EXTEND_EVENT TCMHashLogExtendEvent;
+ PEI_TCM_LOG_EVENT TCMLogEvent;
+ PEI_TCM_PASS_THROUGH_TO_TCM TCMPassThroughToTcm;
+} PEI_TCM_PPI;
+
+extern EFI_GUID gPeiTCMPpiGuid;
+
+#endif \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/PPI/TcgService_PPI.cif b/Core/EM/TCG2/Common/PPI/TcgService_PPI.cif
new file mode 100644
index 0000000..4138030
--- /dev/null
+++ b/Core/EM/TCG2/Common/PPI/TcgService_PPI.cif
@@ -0,0 +1,11 @@
+<component>
+ name = "TcgService_PPI"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common\PPI\"
+ RefName = "TcgService_PPI"
+[files]
+"TcgService\TcgService.c"
+"TcgService\TcgService.h"
+"TcgService\TcgTcmService.h"
+"TcgService\TcgTcmService.c"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/PPI/TpmDevice/TpmDevice.c b/Core/EM/TCG2/Common/PPI/TpmDevice/TpmDevice.c
new file mode 100644
index 0000000..f370d4c
--- /dev/null
+++ b/Core/EM/TCG2/Common/PPI/TpmDevice/TpmDevice.c
@@ -0,0 +1,97 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+
+/*++
+
+ Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Abstract:
+
+ TPM Service PPI GUID as defined in EFI 2.0
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TpmDevice_PPI/TpmDevice/TpmDevice.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TpmDevice_PPI/TpmDevice/TpmDevice.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:59p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 3/31/13 6:42p Fredericko
+// [TAG] EIP113715
+// [Category] Improvement
+// [Description] Please update the copyright header according to AMI
+// copyright rule
+// [Files] Multiple Files
+//
+// 2 5/20/10 8:45a Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TpmDevice.c
+//
+// Description:
+// Defines Tpm Device Ppis' GUID
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include "Efi.h"
+#include "Pei.h"
+
+#include EFI_PPI_DEFINITION( TpmDevice )
+
+EFI_GUID gPeiTpmPpiGuid = PEI_TPM_PPI_GUID;
+
+EFI_GUID_STRING( &gPeiTpmPpiGuid, "Tpm PPI", "Tpm 1.2 Device PPI" );
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/PPI/TpmDevice/TpmDevice.h b/Core/EM/TCG2/Common/PPI/TpmDevice/TpmDevice.h
new file mode 100644
index 0000000..08b4b43
--- /dev/null
+++ b/Core/EM/TCG2/Common/PPI/TpmDevice/TpmDevice.h
@@ -0,0 +1,179 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+ Abstract:
+
+ TPM PPI as defined in EFI 2.0
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TpmDevice_PPI/TpmDevice/TpmDevice.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TpmDevice_PPI/TpmDevice/TpmDevice.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:01p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:59p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 8 3/31/13 6:42p Fredericko
+// [TAG] EIP113715
+// [Category] Improvement
+// [Description] Please update the copyright header according to AMI
+// copyright rule
+// [Files] Multiple Files
+//
+// 7 3/29/11 3:09p Fredericko
+//
+// 6 3/28/11 3:25p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 5 5/20/10 8:45a Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TpmDevice.h
+//
+// Description:
+// Header file for TpmDevice.c[Ppi]
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _PEI_TPMDEVICE_H_
+#define _PEI_TPMDEVICE_H_
+
+#include <TcgEfiTpm.h>
+#include <TcgEfi12.h>
+
+#define PEI_TPM_PPI_GUID \
+ {0xca4853f4, 0xe94b, 0x42b4, 0x86, 0x42, 0xcd, 0xe2, 0x8a, 0x7f, 0xac, 0x2d}
+
+#define TPM_DEACTIVATED_VARIABLE_NAME \
+ L"IsTpmDeactivated"
+
+struct _PEI_TPM_PPI;
+typedef struct _PEI_TPM_PPI PEI_TPM_PPI;
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TPM_INIT)(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TPM_CLOSE)(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TPM_GET_STATUS_INFO)(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices
+ );
+
+
+VOID FillDriverLoc (
+ UINT32 * Offset,
+ EFI_PEI_SERVICES **ps,
+ EFI_GUID *Driveguid );
+
+VOID MAFillDriverLoc (
+ MASTRUCT *Data,
+ EFI_PEI_SERVICES **ps,
+ EFI_GUID *Driveguid );
+
+EFI_STATUS FillDriverLocByFile (
+ UINT32 * Offset,
+ EFI_PEI_SERVICES **ps,
+ EFI_GUID *Driveguid,
+ void **MAStart,
+ UINTN *MASize );
+
+
+EFI_STATUS
+EFIAPI TpmPeiEntry (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices );
+
+
+typedef
+EFI_STATUS
+(EFIAPI * PEI_TPM_TRANSMIT)(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers
+ );
+
+typedef struct _PEI_TPM_PPI
+{
+ PEI_TPM_INIT Init;
+ PEI_TPM_CLOSE Close;
+ PEI_TPM_GET_STATUS_INFO GetStatusInfo;
+ PEI_TPM_TRANSMIT Transmit;
+} PEI_TPM_PPI;
+
+extern EFI_GUID gPeiTpmPpiGuid;
+
+#endif
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/PPI/TpmDevice_PPI.cif b/Core/EM/TCG2/Common/PPI/TpmDevice_PPI.cif
new file mode 100644
index 0000000..57a9c16
--- /dev/null
+++ b/Core/EM/TCG2/Common/PPI/TpmDevice_PPI.cif
@@ -0,0 +1,9 @@
+<component>
+ name = "TpmDevice_PPI"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common\PPI\"
+ RefName = "TpmDevice_PPI"
+[files]
+"TpmDevice\TpmDevice.c"
+"TpmDevice\TpmDevice.h"
+<endComponent> \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/Protocol/TcgService/TcgService.c b/Core/EM/TCG2/Common/Protocol/TcgService/TcgService.c
new file mode 100644
index 0000000..afa983b
--- /dev/null
+++ b/Core/EM/TCG2/Common/Protocol/TcgService/TcgService.c
@@ -0,0 +1,66 @@
+/*++
+
+ Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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.
+
+
+ Abstract:
+
+ TcgService Protocol GUID as defined in TCG_EFI_Protocol_1_20_Final
+
+ See http://trustedcomputinggroup.org for the latest specification
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_Protocol/TcgService/TcgService.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_Protocol/TcgService/TcgService.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 5/20/10 8:44a Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgService.c
+//
+// Description:
+// Defines Tcg Protocol guid
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+#include <Tiano.h>
+
+#include EFI_PROTOCOL_DEFINITION( TcgService )
+
+EFI_GUID gEfiTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID;
+
+EFI_GUID_STRING( &gEfiTcgServiceProtocolGuid,
+ "TcgService",
+ "TCG Services Protocol" );
diff --git a/Core/EM/TCG2/Common/Protocol/TcgService/TcgService.h b/Core/EM/TCG2/Common/Protocol/TcgService/TcgService.h
new file mode 100644
index 0000000..f6f3960
--- /dev/null
+++ b/Core/EM/TCG2/Common/Protocol/TcgService/TcgService.h
@@ -0,0 +1,171 @@
+/*++
+
+ Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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.
+
+ Abstract:
+
+ TCG Service Protocol as defined in TCG_EFI_Protocol_1_20_Final
+
+ See http://trustedcomputinggroup.org for the latest specification
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_Protocol/TcgService/TcgService.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_Protocol/TcgService/TcgService.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 6 3/29/11 3:01p Fredericko
+//
+// 5 3/28/11 3:22p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 4 5/20/10 8:44a Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgService.h
+//
+// Description:
+// Header file for TcgService.c [Protocol]
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCG_SERVICE_PROTOCOL_H_
+#define _TCG_SERVICE_PROTOCOL_H_
+
+#include "TcgEfiTpm.h"
+
+#define EFI_TCG_PROTOCOL_GUID \
+ {0xf541796d, 0xa62e, 0x4954, 0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd}
+
+#define TSS_EVENT_DATA_MAX_SIZE 256
+
+EFI_FORWARD_DECLARATION( EFI_TCG_PROTOCOL );
+
+//
+// Set structure alignment to 1-byte
+//
+#pragma pack (push, 1)
+
+typedef struct
+{
+ UINT8 Major;
+ UINT8 Minor;
+ UINT8 RevMajor;
+ UINT8 RevMinor;
+} TCG_VERSION;
+
+typedef struct _TCG_EFI_BOOT_SERVICE_CAPABILITY
+{
+ UINT8 Size; // Size of this structure
+ TCG_VERSION StructureVersion;
+ TCG_VERSION ProtocolSpecVersion;
+ UINT8 HashAlgorithmBitmap; // Hash algorithms
+ // this protocol is capable of : 01=SHA-1
+ BOOLEAN TPMPresentFlag; // 00h = TPM not present
+ BOOLEAN TPMDeactivatedFlag; // 01h = TPM currently deactivated
+} TCG_EFI_BOOT_SERVICE_CAPABILITY;
+
+typedef UINT32 TCG_ALGORITHM_ID;
+//
+// Restore original structure alignment
+//
+#pragma pack (pop)
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCG_STATUS_CHECK)(
+ IN EFI_TCG_PROTOCOL *This,
+ OUT TCG_EFI_BOOT_SERVICE_CAPABILITY
+ *ProtocolCapability,
+ OUT UINT32 *TCGFeatureFlags,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLocation,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCG_HASH_ALL)(
+ IN EFI_TCG_PROTOCOL *This,
+ IN UINT8 *HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT UINT64 *HashedDataLen,
+ IN OUT UINT8 **HashedDataResult
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCG_LOG_EVENT)(
+ IN EFI_TCG_PROTOCOL *This,
+ IN TCG_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ IN UINT32 Flags
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCG_PASS_THROUGH_TO_TPM)(
+ IN EFI_TCG_PROTOCOL *This,
+ IN UINT32 TpmInputParamterBlockSize,
+ IN UINT8 *TpmInputParamterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCG_HASH_LOG_EXTEND_EVENT)(
+ IN EFI_TCG_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT TCG_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry
+ );
+
+typedef struct _EFI_TCG_PROTOCOL
+{
+ EFI_TCG_STATUS_CHECK StatusCheck;
+ EFI_TCG_HASH_ALL HashAll;
+ EFI_TCG_LOG_EVENT LogEvent;
+ EFI_TCG_PASS_THROUGH_TO_TPM PassThroughToTpm;
+ EFI_TCG_HASH_LOG_EXTEND_EVENT HashLogExtendEvent;
+} EFI_TCG_PROTOCOL;
+
+extern EFI_GUID gEfiTcgProtocolGuid;
+
+#endif
diff --git a/Core/EM/TCG2/Common/Protocol/TcgService/TcgTcmService.c b/Core/EM/TCG2/Common/Protocol/TcgService/TcgTcmService.c
new file mode 100644
index 0000000..fcf3611
--- /dev/null
+++ b/Core/EM/TCG2/Common/Protocol/TcgService/TcgTcmService.c
@@ -0,0 +1,75 @@
+/*++
+
+ Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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.
+
+
+ Abstract:
+
+ TcgService Protocol GUID as defined in TCG_EFI_Protocol_1_20_Final
+
+ See http://trustedcomputinggroup.org for the latest specification
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_Protocol/TcgService/TcgTcmService.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_Protocol/TcgService/TcgTcmService.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 3/29/11 3:03p Fredericko
+//
+// 1 3/28/11 3:20p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 2 5/20/10 8:44a Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgService.c
+//
+// Description:
+// Defines Tcg Protocol guid
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+#include <Tiano.h>
+
+#include EFI_PROTOCOL_DEFINITION( TcgTcmService )
+
+EFI_GUID gEfiTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID;
+
+EFI_GUID_STRING( &gEfiTcgServiceProtocolGuid,
+ "TcgTcmService",
+ "TCM Services Protocol" );
diff --git a/Core/EM/TCG2/Common/Protocol/TcgService/TcgTcmService.h b/Core/EM/TCG2/Common/Protocol/TcgService/TcgTcmService.h
new file mode 100644
index 0000000..829b40b
--- /dev/null
+++ b/Core/EM/TCG2/Common/Protocol/TcgService/TcgTcmService.h
@@ -0,0 +1,167 @@
+/*++
+
+ Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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.
+
+ Abstract:
+
+ TCG Service Protocol as defined in TCG_EFI_Protocol_1_20_Final
+
+ See http://trustedcomputinggroup.org for the latest specification
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_Protocol/TcgService/TcgTcmService.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgService_Protocol/TcgService/TcgTcmService.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 3/29/11 3:02p Fredericko
+//
+// 1 3/28/11 3:20p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 4 5/20/10 8:44a Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgService.h
+//
+// Description:
+// Header file for TcgService.c [Protocol]
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCG_TCM_SERVICE_PROTOCOL_H_
+#define _TCG_TCM_SERVICE_PROTOCOL_H_
+
+#include "TcgEfiTpm.h"
+
+#define EFI_TCG_PROTOCOL_GUID \
+ {0xf541796d, 0xa62e, 0x4954, 0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd}
+
+#define TSS_EVENT_DATA_MAX_SIZE 256
+
+EFI_FORWARD_DECLARATION( EFI_TCM_PROTOCOL );
+// Set structure alignment to 1-byte
+//
+#pragma pack (push, 1)
+
+typedef struct
+{
+ UINT8 Major;
+ UINT8 Minor;
+ UINT8 RevMajor;
+ UINT8 RevMinor;
+} TCM_VERSION;
+
+typedef struct _TCM_EFI_BOOT_SERVICE_CAPABILITY
+{
+ UINT8 Size; // Size of this structure
+ TCM_VERSION StructureVersion;
+ TCM_VERSION ProtocolSpecVersion;
+ UINT8 HashAlgorithmBitmap; // Hash algorithms
+ // this protocol is capable of : 01=SHA-1
+ BOOLEAN TPMPresentFlag; // 00h = TPM not present
+ BOOLEAN TPMDeactivatedFlag; // 01h = TPM currently deactivated
+} TCM_EFI_BOOT_SERVICE_CAPABILITY;
+
+typedef UINT32 TCG_ALGORITHM_ID;
+
+#pragma pack (pop)
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCM_STATUS_CHECK)(
+ IN EFI_TCM_PROTOCOL *This,
+ OUT TCM_EFI_BOOT_SERVICE_CAPABILITY
+ *ProtocolCapability,
+ OUT UINT32 *TCGFeatureFlags,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLocation,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCM_HASH_ALL)(
+ IN EFI_TCM_PROTOCOL *This,
+ IN UINT8 *HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT UINT64 *HashedDataLen,
+ IN OUT UINT8 **HashedDataResult
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCM_LOG_EVENT)(
+ IN EFI_TCM_PROTOCOL *This,
+ IN TCM_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ IN UINT32 Flags
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCM_PASS_THROUGH_TO_TPM)(
+ IN EFI_TCM_PROTOCOL *This,
+ IN UINT32 TpmInputParamterBlockSize,
+ IN UINT8 *TpmInputParamterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TCM_HASH_LOG_EXTEND_EVENT)(
+ IN EFI_TCM_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT TCM_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry
+ );
+
+typedef struct _EFI_TCM_PROTOCOL
+{
+ EFI_TCM_STATUS_CHECK StatusCheck;
+ EFI_TCM_HASH_ALL HashAll;
+ EFI_TCM_LOG_EVENT LogEvent;
+ EFI_TCM_PASS_THROUGH_TO_TPM PassThroughToTpm;
+ EFI_TCM_HASH_LOG_EXTEND_EVENT HashLogExtendEvent;
+} EFI_TCM_PROTOCOL;
+
+extern EFI_GUID gEfiTcgProtocolGuid;
+
+#endif
diff --git a/Core/EM/TCG2/Common/Protocol/TcgService_Protocol.cif b/Core/EM/TCG2/Common/Protocol/TcgService_Protocol.cif
new file mode 100644
index 0000000..a4e469a
--- /dev/null
+++ b/Core/EM/TCG2/Common/Protocol/TcgService_Protocol.cif
@@ -0,0 +1,11 @@
+<component>
+ name = "TcgService_Protocol"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common\Protocol\"
+ RefName = "TcgService_Protocol"
+[files]
+"TcgService\TcgService.c"
+"TcgService\TcgService.h"
+"TcgService\TcgTcmService.h"
+"TcgService\TcgTcmService.c"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/Protocol/TpmDevice/TpmDevice.c b/Core/EM/TCG2/Common/Protocol/TpmDevice/TpmDevice.c
new file mode 100644
index 0000000..4251fb2
--- /dev/null
+++ b/Core/EM/TCG2/Common/Protocol/TpmDevice/TpmDevice.c
@@ -0,0 +1,60 @@
+/*++
+
+ Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Abstract:
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TpmDevice_Protocol/TpmDevice/TpmDevice.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TpmDevice_Protocol/TpmDevice/TpmDevice.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:01p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:59p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 5/20/10 8:46a Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TpmDevice.c
+//
+// Description:
+// Defines Tpm Device Protocol GUID
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include "Efi.h"
+#include EFI_PROTOCOL_DEFINITION( TpmDevice )
+
+EFI_GUID gEfiTpmDeviceProtocolGuid = EFI_TPM_DEVICE_PROTOCOL_GUID;
+
+EFI_GUID_STRING( &gEfiTpmDeviceProtocolGuid,
+ "TPM DXE Driver Protocol",
+ "TPM DXE Driver Protocol" );
diff --git a/Core/EM/TCG2/Common/Protocol/TpmDevice/TpmDevice.h b/Core/EM/TCG2/Common/Protocol/TpmDevice/TpmDevice.h
new file mode 100644
index 0000000..9b9108f
--- /dev/null
+++ b/Core/EM/TCG2/Common/Protocol/TpmDevice/TpmDevice.h
@@ -0,0 +1,197 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Abstract:
+
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TpmDevice_Protocol/TpmDevice/TpmDevice.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TpmDevice_Protocol/TpmDevice/TpmDevice.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:01p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:59p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 7 3/29/11 3:10p Fredericko
+//
+// 6 3/28/11 3:27p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 5 5/20/10 8:47a Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TpmDevice.h
+//
+// Description:
+// Header file for TpmDevice.c[Protocol]
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _EFI_TPM_DEVICE_H_
+#define _EFI_TPM_DEVICE_H_
+
+#include "TcgEfiTpm.h"
+#include "TcgEFI12.h"
+#include "TCGMisc.h"
+#include "TcgCommon.h"
+
+#define EFI_TPM_DEVICE_PROTOCOL_GUID \
+ { 0xde161cfe, 0x1e60, 0x42a1, 0x8c, 0xc3, 0xee, 0x7e, 0xf0, 0x73, 0x52,\
+ 0x12 }
+
+
+EFI_FORWARD_DECLARATION( EFI_TPM_DEVICE_PROTOCOL );
+
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TPM_MP_INIT)(
+ IN EFI_TPM_DEVICE_PROTOCOL *This
+ );
+
+/*++
+
+ Routine Description:
+ This service Open the TPM interface
+
+ Arguments:
+ This - A pointer to the EFI_TPM_MP_DRIVER_PROTOCOL.
+
+ Returns:
+ EFI_SUCCESS - Operation completed successfully
+ EFI_DEVICE_ERROR - The command was unsuccessful
+ EFI_NOT_FOUND - The component was not running
+
+ --*/
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TPM_MP_CLOSE)(
+ IN EFI_TPM_DEVICE_PROTOCOL *This
+ );
+/*++
+
+ Routine Description:
+ This service close the TPM interface and deactivate TPM
+
+ Arguments:
+ This - A pointer to the EFI_TPM_MP_DRIVER_PROTOCOL.
+
+ Returns:
+ EFI_SUCCESS - Operation completed successfully
+ EFI_DEVICE_ERROR - The command was unsuccessful
+ EFI_NOT_FOUND - The component was not running
+
+ --*/
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TPM_MP_GET_STATUS_INFO)(
+ IN EFI_TPM_DEVICE_PROTOCOL *This
+ );
+/*++
+
+ Routine Description:
+ This service get the current status infomation of TPM
+
+ Arguments:
+ This - A pointer to the EFI_TPM_MP_DRIVER_PROTOCOL.
+ ReqStatusType - Requested type of status information, driver or device.
+ Status - Pointer to the returned status.
+
+ Returns:
+ EFI_SUCCESS - Operation completed successfully
+ EFI_DEVICE_ERROR - The command was unsuccessful
+ EFI_INVALID_PARAMETER - One or more of the parameters are incorrect
+ EFI_BUFFER_TOO_SMALL - The receive buffer is too small
+ EFI_NOT_FOUND - The component was not running
+
+ --*/
+
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TPM_MP_TRANSMIT)(
+ IN EFI_TPM_DEVICE_PROTOCOL *This,
+ IN UINTN NoInBuffers,
+ IN TPM_TRANSMIT_BUFFER *InBuffers,
+ IN UINTN NoOutBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutBuffers
+ );
+/*++
+
+ Routine Description:
+ This service transmit data to the TPM and get response from TPM
+
+ Arguments:
+ This - A pointer to the EFI_TPM_MP_DRIVER_PROTOCOL.
+
+ Returns:
+ EFI_SUCCESS - Operation completed successfully
+ EFI_DEVICE_ERROR - The command was unsuccessful
+ EFI_INVALID_PARAMETER - One or more of the parameters are incorrect
+ EFI_BUFFER_TOO_SMALL - The receive buffer is too small
+ EFI_NOT_FOUND - The component was not running
+
+ --*/
+
+
+void Prepare2Thunkproc (
+ UINT32 TcgOffset,
+ UINT16 TcgSelector );
+
+void TcmDxeCallMPDriver (
+ IN UINTN CFuncID,
+ TPMTransmitEntryStruct *CData,
+ UINT32* OUT CRetVal );
+
+void TpmDxeCallMPDriver (
+ IN UINTN CFuncID,
+ TPMTransmitEntryStruct *CData,
+ UINT32* OUT CRetVal );
+
+
+typedef struct _EFI_TPM_DEVICE_PROTOCOL
+{
+ EFI_TPM_MP_INIT Init;
+ EFI_TPM_MP_CLOSE Close;
+ EFI_TPM_MP_GET_STATUS_INFO GetStatusInfo;
+ EFI_TPM_MP_TRANSMIT Transmit;
+} EFI_TPM_DEVICE_PROTOCOL;
+
+extern EFI_GUID gEfiTpmDeviceProtocolGuid;
+
+#endif
diff --git a/Core/EM/TCG2/Common/Protocol/TpmDevice_Protocol.cif b/Core/EM/TCG2/Common/Protocol/TpmDevice_Protocol.cif
new file mode 100644
index 0000000..f24c11c
--- /dev/null
+++ b/Core/EM/TCG2/Common/Protocol/TpmDevice_Protocol.cif
@@ -0,0 +1,9 @@
+<component>
+ name = "TpmDevice_Protocol"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common\Protocol\"
+ RefName = "TpmDevice_Protocol"
+[files]
+"TpmDevice\TpmDevice.c"
+"TpmDevice\TpmDevice.h"
+<endComponent> \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/TCGMisc.h b/Core/EM/TCG2/Common/TCGMisc.h
new file mode 100644
index 0000000..4b1b7a4
--- /dev/null
+++ b/Core/EM/TCG2/Common/TCGMisc.h
@@ -0,0 +1,822 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TCGMisc.h 2 6/11/14 4:13p Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 6/11/14 4:13p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TCGMisc.h $
+//
+// 2 6/11/14 4:13p Fredericko
+// [TAG] EIP173073
+// [Category] Bug Fix
+// [Severity] Important
+// [Symptom] PPI operations will fail
+// [RootCause] EFI spec changes requires that only industry variables
+// should use EfiGlobalVariableGuid
+// [Solution] REF-28609.V2: Clear The TPM via OS test fail /1AQPM037
+// (TPM1.2)
+// [Files] TcgMisc.h
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:59a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 8/30/13 11:06p Fredericko
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 34 3/29/13 9:45p Fredericko
+// [TAG] EIP113715
+// [Category] Improvement
+// [Description] Please update the copyright header according to AMI
+// copyright rule
+// [Files] Multiple Files
+//
+// [TAG] EIP109597
+// [Category] Improvement
+// [Description] Add a switch for TPM PPI flag access via BIOS NVRAM
+// [Files] TCGMisc.h, AmiTcgNvflagSample.c,
+//
+// [TAG] EIP118211
+// [Category] Improvement
+// [Description] Implement ability to skip Physical presence lock in
+// manufacturing mode
+// [Files] TcgPei.c, AmiTcgPlatformDxe.c, AmiTcgNvflagSample.c
+//
+// 33 11/30/12 7:20p Fredericko
+// [TAG] EIP104949
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] UEFI 2.3.1 SCT test failed in Generic\EfiCompliant case.
+// TpmOldvar is not defined in the Spec.
+//
+// 32 5/20/12 2:08p Fredericko
+//
+// 31 4/19/12 8:04p Fredericko
+// Add Fastboot GUID definition for Internal use
+//
+// 30 3/19/12 6:19p Fredericko
+// Changes for TcgPerformance Metrics Improvement.
+// Files Changed: Tcg.sdl, TcgMisc.h, TcgDxe.c, TcgCommon.c, TcgCommon.h,
+// AmiTcgPlatformPeiLib.c, AmiTcgPlatformDxe.c, TcgDxe.dxs
+//
+// 29 2/03/12 5:11p Fredericko
+// [TAG] EIP81665
+// [Category] Improvement
+// [Description] Support for MOR feature improvement
+// [Files] Tcg.sdl, AmiTcgPlatformDxe.c, Tcgdxe.c, Tcglegacy.c
+//
+// 28 1/17/12 11:22a Fredericko
+// Install Tpm_Initialized Ppi in PEI
+//
+// 27 11/01/11 4:15a Fredericko
+// Fixed spelling changes request for physicalPresenceLock and
+// bGlobalLock.
+//
+// 26 8/26/11 12:53p Fredericko
+// [TAG] EIP65710
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] Wrong structure for TPM and TCM permanent flags
+// [RootCause] Lower part of structure was not defined properly since we
+// don't use them in BIOS
+// [Solution] Update structure in TcgMisc.h
+// [Files] TcgMisc.h
+//
+// 25 8/09/11 6:13p Fredericko
+// [TAG] EIP65605
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] None
+// [RootCause] Tpm Permanent flags Structure needs to be updated
+// [Solution] Updated the Tpm Permanent Flags structure
+// [Files] TcgMisc.h
+//
+// 24 7/24/11 10:05p Fredericko
+// [TAG] EIP65177
+// [Category] Spec Update
+// [Severity] Minor
+// [Description] Included sample protocoldefinition to read and set
+// persistent BIOS flags.
+// 2. Also include defines for new smi transactions for Ppi.
+//
+// 23 4/06/11 6:46p Fredericko
+// PPI confirmation Override changes
+//
+// 22 4/01/11 10:50a Fredericko
+// Added TCG legacy GUID for initializing the TPM in legacy mode
+//
+// 21 3/29/11 12:25p Fredericko
+//
+// 20 3/28/11 12:22p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 17 8/04/10 5:21p Fredericko
+// Added #defines for TCG SMI transactions
+//
+// 16 7/09/10 3:26p Fredericko
+// EFI_NULL GUID defined
+//
+// 15 5/19/10 5:18p Fredericko
+// Included File Header
+// Code Beautification
+// EIP 37653
+//
+// 14 3/25/10 7:13p Fredericko
+// Function definition for ResetPPI variables added
+//
+// 13 3/23/10 8:40p Fredericko
+//
+// 12 3/19/10 4:13p Fredericko
+// Generic guid defined for legacy MA Driver, Legacy MP driver and TCG
+// driver hobs
+// Also modified structures Far32Locals, MAStruct, ESPFuncStruc
+//
+// 11 1/14/10 11:43a Fredericko
+// Added TCG NVRAM structure and guid definitions.
+//
+// 10 12/03/09 6:23p Fredericko
+// added UEFI guid definition for MOR
+//
+// 9 6/08/09 4:35p Fredericko
+// typedefs for STANY_FLAGS
+//
+// 8 6/01/09 3:54p Fredericko
+// changes for TCM support.
+//
+// 7 4/30/09 6:13p Fredericko
+// Updated Header Date
+//
+// 6 4/30/09 5:30p Fredericko
+// AMI company Header Address changes
+//
+// 5 3/05/09 2:02p Fredericko
+// Changes for CoreSources dependency
+//
+// 4 2/05/09 4:54p Fredericko
+// Generic TCG structures added and GUIDs added in favor of building
+// without EDK.
+//
+// 3 26/08/08 10:44a Anandakrishnanl
+// Added Sdl Token for the define Equates and Changed the Corresponding
+// Codes
+//
+// 2 2/27/08 5:50p Fredericko
+// TCG structures included
+//
+// 1 7/23/07 10:24a Fredericko
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgMisc.h
+//
+// Description:
+// Miscellaneous Tcg Header file
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+//------------------------------------------------------------------------------
+// OEM INFO for TCG structures(Port OEM info)
+//------------------------------------------------------------------------------
+#ifndef _TCGMISC_H //To Avoid this header get compiled twice
+#define _TCGMISC_H
+#include <EFI.h>
+
+#define EV_SPECIFICATION_IDENTIFIER (UINT32)0x000000012
+//--------------------AMI_PORTING----------------------------------------------
+#define TCG_BIOS_VENDOR "AMI"
+#define TCG_OEM_ID "ALASKA"
+//-----------------------------------------------------------------------------
+#define EFI_TCG_WAKE_EVENT_DATA_HOB_GUID \
+ {0xBBB810BB, 0x5EF0, 0x4E8F, 0xB2, 0x98, 0xAD, 0x74, 0xAA, 0x50, 0xEF, 0x0A}
+
+#define TCG_EFI_HOB_LIST_GUID \
+ { 0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d}
+
+#define EFI_TCG_LOG_HOB_GUID \
+ {0x5f7d4e0e, 0x3d6d, 0x42bc, 0xa9, 0x42, 0xe, 0x91, 0xe8, 0x3e, 0x3c, 0x31}
+
+#define AMI_TCG_EFI_OS_VARIABLE_GUID \
+ {0xa8a2093b, 0xfefa, 0x43c1, 0x8e, 0x62, 0xce, 0x52, 0x68, 0x47, 0x26, 0x5e}
+
+#define AMI_TCG_RESETVAR_HOB_GUID \
+ {0xa8a2093b, 0xfefa, 0x43c1, 0x8e, 0x62, 0xce, 0x52, 0x68, 0x47, 0x26, 0x5e}
+
+#define AMI_TCG_MANUFACTURING_MODE_HOB_GUID \
+ {0x5d7f83ee, 0x88e5, 0x4ea8, 0xbe, 0xe8, 0x23, 0x79, 0xa6, 0x3c, 0xff, 0x8}
+
+#define AMI_TCG_CONFIRMATION_FLAGS_GUID \
+ {0x7d3dceee, 0xcbce, 0x4ea7, 0x87, 0x09, 0x6e, 0x55, 0x2f, 0x1e, 0xdb, 0xde}
+
+#define AMI_TCG_PERM_FLAGS_GUID \
+ {0x2325f2fc, 0x5683, 0x4648, 0x97, 0xc4, 0x9a, 0x52, 0x0d, 0xfb, 0xe3, 0x25}
+
+#define EFI_NULL_GUID \
+ {0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+
+#define TCG_EFI_GLOBAL_VARIABLE_GUID \
+ { \
+ 0x135902e7, 0x9709, 0x4b41, 0x8f, 0xd2, 0x40, 0x69, 0xda, 0xf0, 0x54,\
+ 0x6a \
+ }
+
+#define TCG_VARIABLE_GUID \
+ {0x9868b77b, 0x607e, 0x4cb7, 0xa6, 0xce, 0xe1, 0xd5, 0x29, 0xd4, 0x41, 0x64}
+
+#define EFI_TCM_MPDriver_GUID \
+ { 0x3EB9F0D3, 0x40D0, 0x435b, 0xB6, 0x92, 0x80, 0x91, 0x51, 0x80, 0x7F,\
+ 0xF4}
+
+#define EFI_TCM_MADriver_GUID \
+ { 0xca0d6ff6, 0x62a7, 0x4b1f, 0xbb, 0x90, 0x52, 0xee, 0xca, 0x1, 0xa9,\
+ 0x9f}
+
+#define AMI_TCM_CALLBACK_GUID \
+ { 0x91c74e50, 0x361d, 0x4cda, 0xa1, 0x6b, 0xc9, 0x2b, 0xe4, 0xbf, 0x16,\
+ 0xee}
+
+#define AMI_TPM_LEGACY_GUID \
+ { 0xa1c85085, 0x3053, 0x4c4b, 0xa9, 0xf6, 0x72, 0x4d, 0x22, 0xa7, 0x6e,\
+ 0xf9}
+
+#define PEI_TPM_INITIALIZED_PPI_GUID \
+ { \
+ 0xe9db0d58, 0xd48d, 0x47f6, 0x9c, 0x6e, 0x6f, 0x40, 0xe8, 0x6c, 0x7b, 0x41 \
+ }
+
+#define TPM20_HOB_GUID \
+ { \
+ 0x7cea4f7e, 0x2052, 0x46ed, 0xbe, 0xfd, 0xe2, 0x2a, 0x44, 0xdc, 0x65, 0xe7 \
+ }
+
+#define FAST_BOOT_VARIABLE_GUID \
+ { 0xb540a530, 0x6978, 0x4da7, 0x91, 0xcb, 0x72, 0x7, 0xd7, 0x64, 0xd2, 0x62 }
+
+
+typedef struct
+{
+ UINT8 RQST;
+ UINT8 RCNT;
+ UINT8 ERROR;
+ UINT8 Flag;
+ UINT8 AmiMisc;
+} AMI_PPI_NV_VAR;
+
+typedef struct _mem_in
+{
+ UINTN datat; //0=use_32;1=use_64;2=use_both; 3=dont_use
+ UINT64 address; //Start Memory address
+ UINTN size; //Memory block Size
+} mem_in;
+
+#pragma pack (1)
+typedef struct tdVendorInfoStruct
+{
+ UINT8 *TCGBIOSVENDOR[6];
+ UINT8 *TCGOEMID[8];
+} TCG_VendorInfoStruct;
+
+typedef struct tdPCClientSpecIdEventStruct
+{
+ UINT8 PlatformClass;
+ UINT8 BIOSTypeInterface;
+ UINT8 BIOSTypeMapping;
+ UINT8 SpecVersionMajor;
+ UINT8 SpecVersionMinor;
+ UINT8 SpecErrata;
+ UINTN Reserved;
+ UINTN VendorInfoSize;
+ TCG_VendorInfoStruct *VendorInfo;
+} TCG_PCClientSpecIDEventStruct;
+#pragma pack()
+
+
+#pragma pack (1)
+typedef struct
+{
+ UINT16 Signature; // 0xaa55
+ UINT32 CodeP; // Pointer to beginning of code ( offset to entry point for driver)
+ UINT16 Size; //Total size of the driver in bytes including header
+ UINT32 BaseAddress; //base address of the TPM(as set by BIOS)
+ UINT32 BaseAddress2; //optional second base address of the TPM(as set by BIOS)
+ UINT8 TcgIrqL; //IRQ level
+ UINT8 DMACH; //DMA channel
+ UINT8 checksum; //XOR checksum
+ UINT8 Reserved;
+ UINT32 PCIPFA; //IRQ level
+ UINT32 Other; //Cardbus, USB etc
+ UINT32 TpmPort; //location of TPM configuration port
+ UINT16 VID; //vendor ID
+ UINT16 DID; //device ID
+} MPDRIVER_LEGHEADER;
+#pragma pack ()
+
+
+
+#define EfiBootservicesData 0x04
+
+#pragma pack(1)
+
+typedef struct
+{
+ UINTN NumberOfTables;
+ EFI_CONFIGURATION_TABLE TableEntry[1];
+} TCG_EFI_HANDOFF_TABLE_POINTERS;
+
+//
+// EFI_VARIABLE_DATA
+//
+// This structure serves as the header for measuring variables. The name of the
+// variable (in Unicode format) should immediately follow, then the variable
+// data.
+//
+typedef struct
+{
+ EFI_GUID VariableName;
+ UINTN UnicodeNameLength;
+ UINTN VariableDataLength;
+ CHAR16 UnicodeName[1];
+ INT8 VariableData[1]; // Driver or platform-specific data
+} TCG_EFI_VARIABLE_DATA;
+#pragma pack()
+
+#define INTERNAL_SHA_ARRAY_LENGTH 0x500 //500 bytes per SHA update or extend
+
+//-----------------------------------------------------------------------------
+
+#define EFI_TCG_CAP_HOB_GUID \
+ { 0xd05f8ff9, 0x8498, 0x4673, 0x84, 0x17, 0x7b, 0x9c, 0xce, 0x3d, 0xdb,\
+ 0x9b}
+
+#define EFI_TCG_MPDriver_HOB_GUID \
+ { 0xbaaead09, 0x2a0, 0x4131, 0x9e, 0xd, 0xbc, 0x52, 0x9e, 0xf0, 0xff,\
+ 0x2a}
+
+#define EFI_TCG_MADriver_HOB_GUID \
+ { 0xb58a69fe, 0x163e, 0x4cc0, 0xa4, 0x87, 0x30, 0x4d, 0x34, 0xd5, 0x48,\
+ 0x9f}
+
+#define EFI_TCG_MPDriver_GUID \
+ { 0x0515BC05, 0x2959, 0x4e91, 0x89, 0xC6, 0x6B, 0x3A, 0x3F, 0x1F, 0xCB,\
+ 0x65}
+
+#define EFI_TCG_MADriver_GUID \
+ { 0x92ba9255, 0x2819, 0x4479, 0x86, 0x7a, 0x1c, 0x58, 0xf0, 0x72, 0xc5,\
+ 0xb2}
+
+#define EFI_TCM_MPDriver_GUID \
+ { 0x3EB9F0D3, 0x40D0, 0x435b, 0xB6, 0x92, 0x80, 0x91, 0x51, 0x80, 0x7F,\
+ 0xF4}
+
+#define EFI_TCM_MADriver_GUID \
+ { 0xca0d6ff6, 0x62a7, 0x4b1f, 0xbb, 0x90, 0x52, 0xee, 0xca, 0x1, 0xa9,\
+ 0x9f}
+
+#define EFI_TCG_PEI_READ_ONLY_VARIABLE_PPI_GUID\
+ {0x3cdc90c6, 0x13fb, 0x4a75, 0x9e, 0x79, 0x59, 0xe9, 0xdd, 0x78, 0xb9, 0xfa}
+
+#define AMI_TCG_FV_HOB_GUID \
+ { 0x69275410, 0x9be7, 0x4df2, 0xb7, 0xbb, 0x54, 0x50, 0x65, 0xb6, 0x70,\
+ 0xa4}
+
+#define AMI_TCG_INTERFACE_VAR_GUID \
+ { 0x6e6ebc2d, 0x77ab, 0x46cf, 0xb2, 0xa7, 0xcc, 0x96, 0x8b, 0xe, 0x8a,\
+ 0xf3}
+
+#define AMI_PPI_INTERNAL_VAR_GUID \
+ { 0x78097bb6, 0x48cf, 0x449b, 0x9b, 0xdb, 0xf6, 0x38, 0x49, 0x85, 0x64,\
+ 0x60}
+
+#define AMI_PROTOCOL_INTERNAL_HLXE_GUID \
+ { 0x78092548, 0x48cf, 0x449b, 0x9b, 0xdb, 0xf6, 0x38, 0x49, 0x85, 0x64,\
+ 0x60}
+
+
+#define CMOS_BANK1_INDEXREG 0x70
+#define CMOS_BANK2_INDEXREG 0x72
+#define CMOS_BANK1_SIZE 0x80
+
+// *****************************************************************************************************************************/
+// PHYSICAL PRESENCE INTERFACE
+// *****************************************************************************************************************************/
+#define TCPA_PPI_USERABORT 0xFFF0
+#define TCPA_PPI_BIOSFAIL 0xFFF1
+
+#define TCPA_PPIOP_ENABLE 1
+#define TCPA_PPIOP_DISABLE 2
+#define TCPA_PPIOP_ACTIVATE 3
+#define TCPA_PPIOP_DEACTIVATE 4
+#define TCPA_PPIOP_CLEAR 5
+#define TCPA_PPIOP_ENABLE_ACTV 6
+#define TCPA_PPIOP_DEACT_DSBL 7
+#define TCPA_PPIOP_OWNER_ON 8
+#define TCPA_PPIOP_OWNER_OFF 9
+#define TCPA_PPIOP_ENACTVOWNER 10
+#define TCPA_PPIOP_DADISBLOWNER 11
+#define TCPA_PPIOP_UNOWNEDFIELDUPGRADE 12
+#define TCPA_PPIOP_SETOPAUTH 13
+#define TCPA_PPIOP_CLEAR_ENACT 14
+#define TCPA_PPIOP_SETNOPPIPROVISION_FALSE 15
+#define TCPA_PPIOP_SETNOPPIPROVISION_TRUE 16
+#define TCPA_PPIOP_SETNOPPICLEAR_FALSE 17
+#define TCPA_PPIOP_SETNOPPICLEAR_TRUE 18
+#define TCPA_PPIOP_SETNOPPIMAINTENANCE_FALSE 19
+#define TCPA_PPIOP_SETNOPPIMAINTENANCE_TRUE 20
+#define TCPA_PPIOP_ENABLE_ACTV_CLEAR 21
+#define TCPA_PPIOP_ENABLE_ACTV_CLEAR_ENABLE_ACTV 22
+
+#define PPIXOP_ENABLE 0x01
+#define PPIXOP_DISABLE 0x02
+#define PPIXOP_ACTIVATE 0x04
+#define PPIXOP_DEACTIVATE 0x08
+#define PPIXOP_OWNER_ON 0x10
+#define PPIXOP_OWNER_OFF 0x20
+#define PPIXOP_CLEAR 0x40
+
+#define PPIXOP_EN_FLAG (PPIXOP_ENABLE | PPIXOP_DISABLE)
+#define PPIXOP_A_FLAG (PPIXOP_ACTIVATE | PPIXOP_DEACTIVATE)
+#define PPIXOP_O_FLAG (PPIXOP_OWNER_ON | PPIXOP_OWNER_OFF)
+
+#define PPI_MAX_BASIC_OP 5
+#define PPI_FEATURE_ON 1
+#define PPI_FEATURE_OFF 2
+#define PPI_FEATURE_CHANGE (PPI_FEATURE_ON | PPI_FEATURE_OFF)
+
+
+//
+// TSS event strings
+//
+#define TSS_ACTION_CALLING_INT19 "Calling INT 19h"
+#define TSS_ACTION_RETURNED_INT19 "Returned INT 19h"
+#define TSS_ACTION_RETURNED_INT18 "Return via INT 18h"
+#define TSS_ACTION_BOOTING_BCV_DEVICE "Booting BCV Device "
+#define TSS_ACTION_BOOTING_BEV_DEVICE "Booting BEV Device "
+#define TSS_ACTION_ROM_BASED_SETUP "Entering ROM Based Setup"
+#define TSS_ACTION_BOOTING_PARTIES "Booting to Parties "
+#define TSS_ACTION_USER_PASSWORD "User Password Entered"
+#define TSS_ACTION_ADMINISTRATOR_PASSWORD "Administrator Password Entered"
+#define TSS_ACTION_PASSWORD_FAILURE "Password Failure"
+#define TSS_ACTION_WAKE_EVENT "Wake Event n"
+#define TSS_ACTION_BOOT_SEQ_INTERVENTION "Boot Sequence User Intervention"
+#define TSS_ACTION_CHASSIS_INTRUSION "Chassis Intrusion"
+#define TSS_ACTION_NON_FATAL_ERROR "Non Fatal Error"
+#define TSS_ACTION_OPROM_SCAN "Start Option ROM Scan"
+#define TSS_ACTION_UNHIDEING_OPROM "Unhiding Option ROM Code"
+
+#define TSS_ACTION_IPL_PARTITION "Booting from "
+#define TSS_ACTION_IPL_LEGACY_PARTITION "Booting from Legacy "
+
+
+//-----------------------------------------------------------------------------
+// Internal Tcg Capabilities Headers and Struct
+//-----------------------------------------------------------------------------
+VOID* LocateATcgHob (
+ UINTN NoTableEntries,
+ EFI_CONFIGURATION_TABLE *ConfigTable,
+ EFI_GUID *HOB_guid );
+
+#pragma pack (1)
+typedef struct
+{
+ UINT16 Tag;
+ UINT32 ParamSize;
+ UINT32 CommandCode;
+ UINT32 caparea;
+ UINT32 subCapSize;
+ UINT32 subCap;
+} TPM_GetCapabilities_Input;
+
+typedef struct
+{
+ UINT16 Tag;
+ UINT32 ParamSize;
+ UINT32 RetCode;
+ UINT32 respSize;
+ UINT16 tag;
+ UINT8 disabled;
+ UINT8 ownership;
+ UINT8 deactivated;
+ UINT8 readPubek;
+ UINT8 disableOwnerClear;
+ UINT8 allowMaintenance;
+ UINT8 physicalPresenceLifetimeLock;
+ UINT8 physicalPresenceHWEnable;
+ UINT8 physicalPresenceCMDEnable;
+ UINT8 CEKPUsed;
+ UINT8 TPMpost;
+ UINT8 TPMpostLock;
+ UINT8 FIPS;
+ UINT8 Operator;
+ UINT8 enableRevokeEK;
+ UINT8 nvLocked;
+ UINT8 readSRKPub;
+ UINT8 tpmEstablished;
+ UINT8 maintenanceDone;
+ UINT8 disableFullDALogicInfo;
+} TPM_Capabilities_PermanentFlag;
+
+#define NTC_ORD_GET_TPM_STATUS ((UINT32) 0x20000021)
+typedef struct
+{
+ UINT16 Tag;
+ UINT32 ParamSize;
+ UINT32 RetCode;
+ UINT8 isdisabled;
+ UINT8 isdeactivated;
+ UINT8 isEkSet;
+ UINT8 isOwnerSet;
+ UINT8 preConfigSet;
+ //ami specific we
+ //don't need rest of structure
+} NUVOTON_SPECIFIC_FLAGS;
+
+
+typedef struct
+{
+ UINT16 Tag;
+ UINT32 ParamSize;
+ UINT32 RetCode;
+ UINT32 respSize;
+ UINT16 tag;
+ UINT8 deactivated;
+ UINT8 disableForceClear;
+ UINT8 physicalPresence;
+ UINT8 physicalPresenceLock;
+ UINT8 bGlobalLock;
+} TPM_VOLATILE_FLAGS;
+
+
+
+typedef struct
+{
+ UINT16 Tag;
+ UINT32 ParamSize;
+ UINT32 RetCode;
+ UINT32 respSize;
+ UINT16 tag;
+ UINT8 disabled;
+ UINT8 ownership;
+ UINT8 deactivated;
+ UINT8 readPubek;
+ UINT8 disableOwnerClear;
+ UINT8 physicalPresenceLifetimeLock;
+ UINT8 physicalPresenceHWEnable;
+ UINT8 physicalPresenceCMDEnable;
+ UINT8 CEKPUsed;
+ UINT8 TPMpost;
+ UINT8 TPMpostLock;
+ UINT8 Operator;
+ UINT8 enableRevokeEK;
+ UINT8 nvLocked;
+ UINT8 tpmEstablished;
+ UINT8 writeEkCertLock;
+} TCM_Capabilities_PermanentFlag;
+
+
+typedef struct _TPMTransmitEntryStruct
+{
+ UINT32 pbInBuf;
+ UINT32 dwInLen;
+ UINT32 pbOutBuf;
+ UINT32 dwOutLen;
+} TPMTransmitEntryStruct;
+
+
+#define PCI_EXPANSION_ROM_HEADER_SIGNATURE 0xaa55
+
+#define READTRANSACTION 0x01
+#define WRITETRANSACTION 0x02
+#define GETCONFTRANSACTION 0x03
+#define RQSTVAR 0x10
+#define RCNTVAR 0x20
+#define ERRORVAR 0x30
+#define CONFIRMATION 0x40
+#define ERRORVAR2 0x50
+#define WRITEMOR 0x20
+#define WRITERQST 0x10
+#define WRITEENDRQSTFLAG 0x01
+#define WRITEENDMORFLAG 0x02
+#define READENDCONFLAG 0x03
+#define TRANSACTION_MASK 0x0F
+#define TYPE_MASK 0xF0
+
+typedef struct
+{
+ UINT16 Signature; // 0xaa55
+ UINT16 InitializationSize;
+ UINT32 EfiSignature; // 0x0EF1
+ UINT16 EfiSubsystem;
+ UINT16 EfiMachineType;
+ UINT16 CompressionType;
+ UINT8 Reserved[8];
+ UINT16 EfiImageHeaderOffset;
+ UINT16 PcirOffset;
+} EFI_PCI_EXPANSION_ROM_HEADER;
+
+#define SCAN_F1 EFI_SCAN_F1
+#define SCAN_F2 EFI_SCAN_F2
+#define SCAN_F3 EFI_SCAN_F3
+#define SCAN_F4 EFI_SCAN_F4
+#define SCAN_F5 EFI_SCAN_F5
+#define SCAN_F6 EFI_SCAN_F6
+#define SCAN_F7 EFI_SCAN_F7
+#define SCAN_F8 EFI_SCAN_F8
+#define SCAN_F9 EFI_SCAN_F9
+#define SCAN_F10 EFI_SCAN_F10
+#define SCAN_F11 EFI_SCAN_F11
+#define SCAN_F12 EFI_SCAN_F12
+#define SCAN_ESC EFI_SCAN_ESC
+
+typedef struct _TCG_LOG_HOB_
+{
+ UINT32 TableMaxSize;
+ UINT32 TableSize;
+ UINT32 EventNum;
+ UINT32 Reserved;
+} TCG_LOG_HOB;
+
+#pragma pack()
+//--------------------------------------------------------------------------
+// END_OF Internal Tcg Capabilities Headers and Struct
+//--------------------------------------------------------------------------
+
+//--------------------------------------------------------------------------
+//USED PE/COFF image headers
+//--------------------------------------------------------------------------
+typedef struct
+{
+ UINTN Signature;
+ BOOLEAN FreeBuffer;
+ VOID *Source;
+ UINTN SourceSize;
+} IMAGE_FILE_HANDLE;
+
+
+#define EFI_IMAGE_ERROR_SUCCESS 0
+#define EFI_IMAGE_ERROR_IMAGE_READ 1
+#define EFI_IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2
+//--------------------------------------------------------------------------
+//--------------------------------------------------------------------------
+//
+//
+//----------------------------------------------------------------------------
+// Description: TCG ACPI table. Requires PORTING: OEM data
+// Input: None
+// Output: None
+//----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//PORTING STARTS
+//-----------------------------------------------------------------------------
+#define TCG_TBL_REV 0x02
+#define TCG_OEMID "APTIO4" //; 6 charachters that identify the OEM
+#define TCG_TBL_OEM_ID 0x4653414150414E //"NAPAASF" //; 8 charachters as OEM manufacturer model ID
+#define TCG_TBL_OEM_REV 01 //; DWORD - Revision Number of this table,
+#define TCG_CREATOR_ID 0x5446534D // "MSFT"
+#define TCG_CREATOR_REVISION 0x01000013 // TBD
+#define TCG_PLATFORM_CLASS 0x0
+
+//-----------------------------------------------------------------------------
+//Assuming we are in 32bit mode in PEI and the selectors are set up in real mode
+//-----------------------------------------------------------------------------
+#define SEL_flatDS 0x8
+#define SEL_flatCS 0x10
+
+typedef struct
+{
+ UINT32 Offset;
+ UINT16 Selector;
+ UINT32 Codep;
+ UINT32 Size;
+} FAR32LOCALS;
+
+typedef struct
+{
+ UINT32 Offset;
+ UINT16 Selector;
+ UINT32 Codep;
+} MASTRUCT;
+
+typedef struct
+{
+ UINT16 Tag;
+ UINT32 ParamSize;
+ UINT32 RetCode;
+ UINT32 respSize;
+ UINT16 tag;
+ BOOLEAN postInitialise;
+ UINT32 localityModifier;
+ BOOLEAN transportExclusive;
+ BOOLEAN TOSPresent;
+} IntTPM_STANY_FLAGS;
+
+
+typedef struct
+{
+ UINT32 ReturnAddress;
+ UINT32 Header;
+ UINT8 FuncNum;
+} ESPFUNCSTRUCT;
+
+
+typedef struct
+{
+ UINT8 NoPpiProvision;
+ UINT8 NoPpiClear;
+ UINT8 NoPpiMaintenance;
+} PERSISTENT_BIOS_TPM_FLAGS;
+
+typedef struct
+{
+ UINT8 Interface : 1; //0=TpmNv, 1= BIOSNv
+ UINT8 Reserved1 : 1;
+ UINT8 Reserved2 : 1;
+ UINT8 Reserved3 : 1;
+ UINT8 Reserved4 : 1;
+ UINT8 Reserved5 : 1;
+ UINT8 Reserved6 : 1;
+ UINT8 Reserved7 : 1;
+} INTERNAL_BIOS_TPM_PPI_INTERFACE;
+
+
+typedef
+UINT8
+(EFIAPI * CONFIRM_USER)(
+);
+
+typedef struct _AMI_CONFIRMATION_OVERRIDE_PROTOCOL
+{
+ CONFIRM_USER ConfirmUser;
+} AMI_CONFIRMATION_OVERRIDE_PROTOCOL;
+
+
+typedef
+EFI_STATUS
+(EFIAPI * READ_PERSISTENT_BIOS_TPM_FLAGS)(
+ PERSISTENT_BIOS_TPM_FLAGS *
+);
+
+typedef
+EFI_STATUS
+(EFIAPI * SET_PERSISTENT_BIOS_TPM_FLAGS)(
+ PERSISTENT_BIOS_TPM_FLAGS *
+);
+
+
+typedef struct _TPM_PERM_FLAGS
+{
+ TPM_Capabilities_PermanentFlag Capabilities;
+} TPM_PERM_FLAGS;
+
+typedef struct _PERSISTENT_BIOS_TPM_MANAGEMENT_FLAGS_PROTOCOL
+{
+ READ_PERSISTENT_BIOS_TPM_FLAGS ReadBiosTpmflags;
+ SET_PERSISTENT_BIOS_TPM_FLAGS SetBiosTpmflags;
+} PERSISTENT_BIOS_TPM_MANAGEMENT_FLAGS_PROTOCOL;
+
+
+#define MA_FUNCTION_INIT 0x01
+#define MP_FUNCTION_CLOSE 0x02
+#define MP_FUNCTION_GET_STATUS 0x03
+#define MP_FUNCTION_TRANSMIT 0x04
+//-----------------------------------------------------------------------------
+//PORTING ENDS
+//-----------------------------------------------------------------------------
+
+#endif
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/TCGSmm/TCGSmm.DXS b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.DXS
new file mode 100644
index 0000000..fe7043b
--- /dev/null
+++ b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.DXS
@@ -0,0 +1,84 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TCGSmm/TCGSmm.DXS 1 4/21/14 2:18p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:18p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TCGSmm/TCGSmm.DXS $
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 2 12/10/13 12:59p Fredericko
+// Modify dependency's
+//
+// 1 10/08/13 12:05p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 7/11/13 6:14p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20).
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 7/25/11 3:21a Fredericko
+// [TAG] EIP65177
+// [Category] Spec Update
+// [Severity] Minor
+// [Description] TCG Ppi Sec ver 1.2 update
+//
+// 2 5/20/10 8:54a Fredericko
+//
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TCGSmm.dxs
+//
+// Description:
+// Dependency for TcgSmm
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include "TCGSmm.h"
+
+DEPENDENCY_START
+ EFI_SMM_SW_DISPATCH_PROTOCOL_GUID
+DEPENDENCY_END
+
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//************************************************************************* \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/TCGSmm/TCGSmm.c b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.c
new file mode 100644
index 0000000..5740605
--- /dev/null
+++ b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.c
@@ -0,0 +1,956 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TCGSmm/TCGSmm.c 2 6/09/14 5:01p Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 6/09/14 5:01p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TCGSmm/TCGSmm.c $
+//
+// 2 6/09/14 5:01p Fredericko
+// Changes for SetVariable vulnerability during Runtime
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 4 3/17/14 3:23p Fredericko
+//
+// 3 3/14/14 3:53p Fredericko
+//
+// 2 12/10/13 12:58p Fredericko
+// Locate Tree Protocol as well
+//
+// 1 10/08/13 12:05p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 8/30/13 11:02p Fredericko
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 17 7/31/12 6:27p Fredericko
+// [TAG] EIP94589
+// [Category] Improvement
+// [Description] Use better variable names in TcgSmm.c
+// [Files] TcgSmm.c
+//
+// 16 5/20/12 2:12p Fredericko
+//
+// 15 5/09/12 5:31p Fredericko
+// Change Port address to support 16bit port addresses. Some Chipsets
+// require this.
+//
+// 14 3/19/12 6:37p Fredericko
+// [TAG] EIP82866
+// [Description] AMIUEFI: Implement the NoPPIClear flag and provide
+// operations to set/clear the value or a BIOS config option - Windows
+// Partner Bug Management Bug #679996
+// [Files] AmiTcgNvFlagSample.c, AmiTcgNvFlagSample.sdl,
+// AmiTcgPlatformDxe.c
+//
+// 13 12/12/11 1:08p Fredericko
+// [TAG] EIP59683
+// [Category] Improvement
+// [Description] Allow selection between writing to SMI port as a word
+// or as a Byte.
+// Some platforms might require word writes to the SMI Status port.
+// [Files] Tcg.cif, Tcg.sdl, Tcg_ppi1_2_Ex.asl, TcgSmm.mak, TcgSmm.c
+//
+// 12 12/07/11 4:27p Fredericko
+//
+// 11 12/07/11 4:26p Fredericko
+// [TAG] EIP59683
+// [Category] Improvement
+// [Description] Allow selection between writing to SMI port as a word
+// or as a Byte.
+// Some platforms might require word writes to the SMI Status port.
+// [Files] Tcg.cif, Tcg.sdl, Tcg_ppi1_2_Ex.asl, TcgSmm.mak, TcgSmm.c
+//
+// 10 8/10/11 4:30p Fredericko
+// [TAG] EIPEIP66468
+// [Category] Spec Update
+// [Severity] Minor
+// [Description] 1. Added some more boundary checking for unsupported
+// functions and for handling of Ppi 0
+// [Files] 1. TcgSmm.c
+//
+// 9 8/09/11 6:29p Fredericko
+// [TAG] EIP66468
+// [Category] Spec Update
+// [Severity] Minor
+// [Description] 1. Changes for Tcg Ppi 1.2 support.
+// [Files] 1 TcgSmm.h
+// 2.TcgSmm.c
+// 3.Tcg_ppi1_2.asl
+// 4. AmiTcgNvflagsSample.c
+// 5. AmiTcgPlatformPeiLib.c
+// 6. AmiTcgPlatformDxe.sdl
+// 7. AmiTcgPlatformDxe.c
+//
+// 8 7/25/11 3:20a Fredericko
+// [TAG] EIP65177
+// [Category] Spec Update
+// [Severity] Minor
+// [Description] TCG Ppi Sec ver 1.2 update
+//
+// 7 2/16/11 10:37a Fredericko
+// [TAG] EIP54014
+// [Category] BUG FIX
+// [Severity] HIGH
+// [Symptom] TPM initialize failed using win7 tool tpm.msc after drive
+// bitlocker test.
+// [RootCause] wrong size used for getvariable
+// [Solution] Use correct size
+// [Files] TCGSmm.c
+//
+// 6 8/23/10 4:21p Fredericko
+// Code Clean up. Removed port 80 checkpoint writes from code.
+//
+// 5 8/09/10 2:34p Fredericko
+// Added NVRAM writes functions for TCG PPI support. Moved from TcgBoard
+// component
+//
+// 4 8/04/10 5:07p Fredericko
+// Changed AMI interface to use only one SMI value instead of 3
+//
+// 3 5/20/10 8:54a Fredericko
+// Included File Header
+// Included File Revision History
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TCGSmm.c
+//
+// Description:
+// Function definition file for TCGSMM subcomponent
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+#include "TCGSmm.h"
+#include <Tpm20Includes\TrEEProtocol.h>
+#include <Setup.h>
+
+#if WORD_ACCESS_SMI_PORT == 0x01
+void DisablePlatformSMI();
+#endif
+
+VOID NVOSWrite_PPI_request (
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext );
+
+VOID NVOSWrite_MOR_request (
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext );
+
+VOID NVOSRead_PPI_request (
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext );
+
+EFI_STATUS GetNextGuidHob(
+ IN OUT VOID **HobStart,
+ IN EFI_GUID * Guid,
+ OUT VOID **Buffer,
+ OUT UINTN*BufferSize OPTIONAL )
+{
+ return EFI_SUCCESS;
+}
+
+typedef EFI_STATUS (*SHOW_BOOT_TIME_VARIABLES)(BOOLEAN Show);
+
+static EFI_GUID AmiNvramControlProtocolGuid = { 0xf7ca7568, 0x5a09, 0x4d2c, { 0x8a, 0x9b, 0x75, 0x84, 0x68, 0x59, 0x2a, 0xe2 } };
+typedef EFI_STATUS (*SHOW_BOOT_TIME_VARIABLES)(BOOLEAN Show);
+
+typedef struct{
+ SHOW_BOOT_TIME_VARIABLES ShowBootTimeVariables;
+} AMI_NVRAM_CONTROL_PROTOCOL;
+
+
+AMI_NVRAM_CONTROL_PROTOCOL *NvramControl = NULL;
+
+
+UINT8 ReadSmiPort(UINT16 Port)
+{
+ #if WORD_ACCESS_SMI_PORT == 0x00
+ return (IoRead8(Port ));
+ #else
+ if(Port == (TCGSMIDATAPORT)){
+ Port = TCGSMIPORT;
+ return ((UINT8)(((IoRead16( Port ) & 0xFF00))>> 8));
+ }
+ else{
+ return ((UINT8)(IoRead16( Port ) & 0x00FF));
+ }
+ #endif
+}
+
+
+VOID WritebyteSmiPort(UINT16 Port, UINT8 data)
+{
+ UINT16 SmiPortVal = 0;
+
+ #if WORD_ACCESS_SMI_PORT == 0x00
+ IoWrite8(Port, data );
+ #else
+ SmiPortVal = ReadSmiPort (TCGSMIPORT);
+ if(Port == TCGSMIDATAPORT)
+ {
+ SmiPortVal |= (data << 8);
+ }else{
+ return; //don't change current SMI value
+ }
+ Port = TCGSMIPORT;
+ DisablePlatformSMI(); //put this function under board so that it is added to the CSP lib
+ IoWrite16(Port, SmiPortVal );
+ EnablePlatformSMI();
+ #endif
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: NVOSread_PPI_request
+//
+// Description: Returns TCG PPI variable values to the Operating system
+//
+//
+// Input: IN EFI_HANDLE DispatchHandle,
+// IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
+//
+// Output: VOID
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+VOID NVOSRead_PPI_request(
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext )
+{
+ UINTN Size = sizeof(AMI_PPI_NV_VAR);
+ AMI_PPI_NV_VAR Temp;
+ UINT8 Read_value = 0;
+ EFI_STATUS Status;
+
+ Read_value = ReadSmiPort( TCGSMIDATAPORT );
+
+ if (NvramControl == NULL)
+ NvramControl = GetSmstConfigurationTable(&AmiNvramControlProtocolGuid);
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(TRUE);
+
+ Status = pRS->GetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ NULL, \
+ &Size, \
+ &Temp );
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+
+ if(Status){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xFF );
+ return;
+ }
+
+ switch (Read_value & TYPE_MASK ){
+ case RQSTVAR:
+ WritebyteSmiPort( TCGSMIDATAPORT, Temp.RQST );
+ break;
+ case RCNTVAR:
+ WritebyteSmiPort( TCGSMIDATAPORT, Temp.RCNT );
+ break;
+ case ERRORVAR:
+ WritebyteSmiPort( TCGSMIDATAPORT, Temp.ERROR );
+ case ERRORVAR2:
+ WritebyteSmiPort( TCGSMIDATAPORT, Temp.AmiMisc );
+ break;
+ default:
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xFF );
+ break;
+ }
+}
+
+//****************************************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: NVWrite_PPI_request
+//
+// Description: Writes TCG PPI variable values to NVRAM on SMI request the Operating system
+//
+//
+// Input: IN EFI_HANDLE DispatchHandle,
+// IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
+//
+// Output: VOID
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//****************************************************************************************
+VOID NVOSWrite_PPI_request(
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext )
+{
+ UINTN Size = sizeof(AMI_PPI_NV_VAR);
+ AMI_PPI_NV_VAR Temp;
+ EFI_STATUS Status;
+ UINT8 Read_value = 0;
+ UINT32 attrib = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+
+ Read_value = ReadSmiPort( TCGSMIDATAPORT );
+
+ if( Read_value == TCPA_PPIOP_UNOWNEDFIELDUPGRADE
+ || Read_value == TCPA_PPIOP_SETOPAUTH
+ || Read_value == TCPA_PPIOP_SETNOPPIMAINTENANCE_FALSE
+ || Read_value == TCPA_PPIOP_SETNOPPIMAINTENANCE_TRUE
+ || Read_value > TCPA_PPIOP_ENABLE_ACTV_CLEAR_ENABLE_ACTV)
+ {
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xF1 );
+ return;
+ }
+
+ if(Read_value >= 0 && Read_value < 23)
+ {
+ Temp.RQST = Read_value;
+ Temp.RCNT = Read_value;
+ Temp.ERROR = 0;
+ Temp.Flag = 0;
+ Temp.AmiMisc = 0;
+
+ if (NvramControl == NULL)
+ NvramControl = GetSmstConfigurationTable(&AmiNvramControlProtocolGuid);
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(TRUE);
+
+ Status = pRS->SetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ attrib, \
+ Size, \
+ &Temp );
+
+ if(Status == EFI_INVALID_PARAMETER)
+ {
+ Status = pRS->SetVariable(L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ 0, \
+ 0, \
+ NULL);
+
+ if(EFI_ERROR(Status)){
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ return;
+ }
+
+ Status = pRS->SetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ attrib, \
+ Size, \
+ &Temp );
+ }
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+
+ if(Status){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xFF );
+ return;
+ }
+ }else{
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xF1 );
+ return;
+ }
+}
+
+
+
+#if defined TCGPPISPEC_1_2_SUPPORT && TCGPPISPEC_1_2_SUPPORT == 1
+//****************************************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: Read_User_Confirmation_Status
+//
+// Description: Reads the user confirmation satus for PPI requests
+//
+//
+// Input: IN EFI_HANDLE DispatchHandle,
+// IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
+//
+// Output: VOID
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//****************************************************************************************
+VOID Read_User_Confirmation_Status(
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext )
+{
+ UINTN Size = sizeof(PERSISTENT_BIOS_TPM_FLAGS);
+ UINTN BiosSize = sizeof(AMI_PPI_NV_VAR);
+ AMI_PPI_NV_VAR Temp;
+ PERSISTENT_BIOS_TPM_FLAGS TpmNvFlags;
+ UINT8 Read_value = 0;
+ EFI_STATUS Status;
+ SETUP_DATA SetupDataBuffer;
+ UINTN SetupVariableSize = sizeof(SETUP_DATA);
+ UINT32 SetupVariableAttributes=0;
+ EFI_GUID gSetupGuid = SETUP_GUID;
+ UINT32 attrib = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+ if (NvramControl == NULL)
+ NvramControl = GetSmstConfigurationTable(&AmiNvramControlProtocolGuid);
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(TRUE);
+
+
+ Read_value = ReadSmiPort( TCGSMIDATAPORT );
+
+ Status = pRS->GetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ NULL, \
+ &BiosSize, \
+ &Temp );
+
+ //reset ppi transaction flag
+ Temp.Flag = 0;
+
+ Status = pRS->SetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ attrib, \
+ BiosSize, \
+ &Temp );
+
+ if(Status == EFI_INVALID_PARAMETER)
+ {
+ Status = pRS->SetVariable(L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ 0, \
+ 0, \
+ NULL);
+
+ if(EFI_ERROR(Status)){
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ return;
+ }
+
+ Status = pRS->SetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ attrib, \
+ BiosSize, \
+ &Temp );
+ }
+
+
+ Status = pRS->GetVariable( L"TPMPERBIOSFLAGS", \
+ &SmmFlagsStatusguid, \
+ NULL, \
+ &Size, \
+ &TpmNvFlags );
+
+ Status = pRS->GetVariable (
+ L"Setup",
+ &gSetupGuid,
+ &SetupVariableAttributes,
+ &SetupVariableSize,
+ &SetupDataBuffer);
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+
+ if(Read_value >= 0 && Read_value < 23)
+ {
+ if(Read_value == 0 )
+ {
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x4 );
+ return;
+ }
+
+ if( Read_value == TCPA_PPIOP_UNOWNEDFIELDUPGRADE
+ || Read_value == TCPA_PPIOP_SETOPAUTH
+ || Read_value == TCPA_PPIOP_SETNOPPIMAINTENANCE_FALSE
+ || Read_value == TCPA_PPIOP_SETNOPPIMAINTENANCE_TRUE
+ || Read_value > TCPA_PPIOP_ENABLE_ACTV_CLEAR_ENABLE_ACTV)
+ {
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x0 );
+ return;
+ }else if(Read_value == TCPA_PPIOP_CLEAR || Read_value == TCPA_PPIOP_ENABLE_ACTV_CLEAR )
+ {
+ if(TpmNvFlags.NoPpiClear == TRUE){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x4 );
+ }else{
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x3 );
+ }
+ return;
+ }else if(Read_value == TCPA_PPIOP_CLEAR_ENACT || Read_value == TCPA_PPIOP_ENABLE_ACTV_CLEAR_ENABLE_ACTV)
+ {
+ if(TpmNvFlags.NoPpiClear == TRUE && TpmNvFlags.NoPpiProvision == TRUE ){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x4 );
+ }else{
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x3 );
+ }
+ return;
+ }else if(Read_value == TCPA_PPIOP_SETNOPPIPROVISION_FALSE || Read_value == TCPA_PPIOP_SETNOPPIPROVISION_TRUE)
+ {
+ if(Read_value == TCPA_PPIOP_SETNOPPIPROVISION_TRUE ){
+ if(SetupDataBuffer.Tpm20Device == 1){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x4 );
+ }else{
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x3 );
+ }
+ }else{
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x4 );
+ }
+ return;
+ }else if(Read_value == TCPA_PPIOP_SETNOPPICLEAR_FALSE || Read_value == TCPA_PPIOP_SETNOPPICLEAR_TRUE)
+ {
+ if(Read_value == TCPA_PPIOP_SETNOPPICLEAR_TRUE ){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x3 );
+ }else{
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x4 );
+ }
+ return;
+ }
+ else if(TpmNvFlags.NoPpiProvision == TRUE)
+ {
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x4 );
+ }else
+ {
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x3 );
+ }
+ }else{
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x0 );
+ }
+}
+#endif
+
+
+
+//****************************************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: NVOSWrite_MOR_request
+//
+// Description: Writes TCG PPI MOR variable to NVRAM on SMI request the Operating system
+//
+//
+// Input: IN EFI_HANDLE DispatchHandle,
+// IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
+//
+// Output: VOID
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//****************************************************************************************
+VOID NVOSWrite_MOR_request(
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext )
+{
+ UINT8 mor = 0;
+ UINTN MorSize = sizeof(mor);
+ EFI_STATUS Status;
+ CHAR16 UefiMor[] = L"MemoryOverwriteRequestControl";
+ EFI_GUID MorUefiGuid = MEMORY_ONLY_RESET_CONTROL_GUID;
+ UINT8 Read_value = 0;
+ UINTN PpiVarSize = sizeof(AMI_PPI_NV_VAR);
+ AMI_PPI_NV_VAR Temp;
+ UINT32 attrib = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+
+ Read_value = ReadSmiPort( TCGSMIDATAPORT );
+
+ if (NvramControl == NULL)
+ NvramControl = GetSmstConfigurationTable(&AmiNvramControlProtocolGuid);
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(TRUE);
+
+
+ Status = pRS->SetVariable( UefiMor, \
+ &MorUefiGuid, \
+ EFI_VARIABLE_NON_VOLATILE \
+ | EFI_VARIABLE_RUNTIME_ACCESS \
+ | EFI_VARIABLE_BOOTSERVICE_ACCESS, \
+ MorSize, \
+ &Read_value );
+
+ if(Status){
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xFF );
+ return;
+ }
+
+ Status = pRS->GetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ NULL, \
+ &PpiVarSize, \
+ &Temp );
+
+ if(Status){
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xFF );
+ return;
+ }
+
+ Temp.Flag = 0;
+
+ Status = pRS->SetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ attrib, \
+ PpiVarSize, \
+ &Temp );
+
+ if(Status == EFI_INVALID_PARAMETER)
+ {
+ Status = pRS->SetVariable(L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ 0, \
+ 0, \
+ NULL);
+
+ if(EFI_ERROR(Status)){
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ return;
+ }
+
+ Status = pRS->SetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ attrib, \
+ PpiVarSize, \
+ &Temp);
+ }
+
+ if(Status){
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xFF );
+ return;
+ }
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgCommonSetFlag
+//
+// Description: Common function to set flag for PPI write transactions
+//
+//
+// Input: UINT8 Data
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS TcgCommonSetFlag(
+ UINT8 Data
+)
+{
+ EFI_STATUS Status;
+ UINTN Size = sizeof(AMI_PPI_NV_VAR);
+ AMI_PPI_NV_VAR Temp;
+ UINT32 attrib = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS;
+
+
+ if (NvramControl == NULL)
+ NvramControl = GetSmstConfigurationTable(&AmiNvramControlProtocolGuid);
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(TRUE);
+
+ Status = pRS->GetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ NULL, \
+ &Size, \
+ &Temp );
+
+ if(Status){
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ return Status;
+ }
+
+ if((Data & TYPE_MASK) == WRITERQST){
+
+ Temp.Flag = WRITEENDRQSTFLAG;
+
+ }
+ else if((Data & TYPE_MASK) == WRITEMOR){
+
+ Temp.Flag = WRITEENDMORFLAG;
+ }
+#if defined TCGPPISPEC_1_2_SUPPORT && TCGPPISPEC_1_2_SUPPORT == 1
+ else if((Data & TYPE_MASK) == CONFIRMATION){
+
+ Temp.Flag = READENDCONFLAG;
+ }
+#endif
+
+ Status = pRS->SetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ attrib, \
+ Size, \
+ &Temp );
+
+ if(Status == EFI_INVALID_PARAMETER)
+ {
+ Status = pRS->SetVariable(L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ 0, \
+ 0, \
+ NULL);
+
+ if(EFI_ERROR(Status)){
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ return Status;
+ }
+
+ Status = pRS->SetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ attrib, \
+ Size, \
+ &Temp);
+ }
+
+
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+ return Status;
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgSmiCommonHandler
+//
+// Description: Common function to handle TCG SMI's
+//
+//
+// Input: IN EFI_HANDLE DispatchHandle,
+// IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext
+//
+// Output: VOID
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+VOID TcgSmiCommonHandler(
+ IN EFI_HANDLE DispatchHandle,
+ IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext )
+{
+ EFI_STATUS Status;
+ UINTN Size = sizeof(AMI_PPI_NV_VAR);
+ AMI_PPI_NV_VAR Temp;
+ UINT8 Data;
+
+
+ Data = ReadSmiPort( TCGSMIDATAPORT );
+
+ if (NvramControl == NULL)
+ NvramControl = GetSmstConfigurationTable(&AmiNvramControlProtocolGuid);
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(TRUE);
+
+ Status = pRS->GetVariable( L"AMITCGPPIVAR", \
+ &SmmtcgefiOsVariableGuid, \
+ NULL, \
+ &Size, \
+ &Temp );
+
+ if (NvramControl) NvramControl->ShowBootTimeVariables(FALSE);
+
+ if(Status){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xFF );
+ return;
+ }
+
+#if defined TCGPPISPEC_1_2_SUPPORT && TCGPPISPEC_1_2_SUPPORT == 1
+ if(Temp.Flag == READENDCONFLAG){
+ Read_User_Confirmation_Status ( DispatchHandle, DispatchContext );
+ return;
+ }
+#endif
+
+ if(Temp.Flag == WRITEENDRQSTFLAG){
+
+ NVOSWrite_PPI_request( DispatchHandle, DispatchContext );
+ return;
+
+ }else if(Temp.Flag == WRITEENDMORFLAG){
+
+ NVOSWrite_MOR_request( DispatchHandle, DispatchContext );
+ return;
+ }
+
+ switch(Data & TRANSACTION_MASK)
+ {
+ case READTRANSACTION:
+ NVOSRead_PPI_request( DispatchHandle, DispatchContext);
+ break;
+ case WRITETRANSACTION:
+ Status = TcgCommonSetFlag(Data);
+ if(Status){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0xFF );
+ }
+ break;
+#if defined TCGPPISPEC_1_2_SUPPORT && TCGPPISPEC_1_2_SUPPORT == 1
+ case GETCONFTRANSACTION:
+ Status = TcgCommonSetFlag(Data);
+ if(Status){
+ WritebyteSmiPort( TCGSMIDATAPORT, 0x00 );
+ }
+ break;
+#endif
+ default:
+ break;
+ }
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: HelpRegisterPPISMI
+//
+// Description: Common function to handle TCG SMI's
+//
+//
+// Input: IN EFI_HANDLE ImageHandle,
+// IN EFI_SYSTEM_TABLE *SystemTable
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS HelpRegisterPPISMI(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_SMM_SW_DISPATCH_PROTOCOL *pSwDispatch;
+ EFI_SMM_SW_DISPATCH_CONTEXT SwContext;
+ EFI_HANDLE Handle;
+ EFI_HANDLE DummyHandle = NULL;
+ EFI_STATUS Status;
+
+ VERIFY_EFI_ERROR( pBS->LocateProtocol(
+ &gEfiSmmSwDispatchProtocolGuid, NULL, &pSwDispatch
+ ));
+
+ TRACE((TRACE_ALWAYS, "SMIFlash: Registering TCG SMI functions at offset\n"));
+
+ SwContext.SwSmiInputValue = PPI_OFFSET;
+ Status = pSwDispatch->Register( pSwDispatch,
+ TcgSmiCommonHandler,
+ &SwContext,
+ &Handle );
+
+ ASSERT_EFI_ERROR( Status );
+
+ if ( EFI_ERROR( Status )){
+ return EFI_SUCCESS;
+ }
+
+ return Status;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TCGSmmInit
+//
+// Description: Entry point for subcomponent
+//
+// Input: IN EFI_HANDLE ImageHandle,
+// IN EFI_SYSTEM_TABLE *SystemTable
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS TCGSmmInit(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ EFI_SMM_SW_DISPATCH_PROTOCOL *SwDispatch;
+ EFI_GUID gTreeprotocol = EFI_TREE_PROTOCOL_GUID;
+ EFI_GUID gAmiTcgPltformProtocol = AMI_TCG_PLATFORM_PROTOCOL_GUID;
+ EFI_TREE_PROTOCOL *TreeProtocol = NULL;
+
+ InitAmiLib( ImageHandle, SystemTable );
+ Status = pBS->LocateProtocol( &SwDispatchProtocolGuid, NULL, &SwDispatch );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ Status = pBS->LocateProtocol(&gTreeprotocol, NULL, &TreeProtocol);
+ if(EFI_ERROR(Status)){
+ Status = pBS->LocateProtocol(&gAmiTcgPltformProtocol, NULL, &TreeProtocol);
+ if(EFI_ERROR(Status))return Status;
+ }
+
+ return InitSmmHandler( ImageHandle, SystemTable, HelpRegisterPPISMI, NULL );
+}
+
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Core/EM/TCG2/Common/TCGSmm/TCGSmm.cif b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.cif
new file mode 100644
index 0000000..1410191
--- /dev/null
+++ b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.cif
@@ -0,0 +1,12 @@
+<component>
+ name = "TCGSmm"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common\TCGSmm\"
+ RefName = "TCGSmm"
+[files]
+"TCGSmm.sdl"
+"TCGSmm.mak"
+"TCGSmm.h"
+"TCGSmm.c"
+"TCGSmm.DXS"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/TCGSmm/TCGSmm.h b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.h
new file mode 100644
index 0000000..45e1d3e
--- /dev/null
+++ b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.h
@@ -0,0 +1,104 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TCGSmm/TCGSmm.h 1 4/21/14 2:18p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:18p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TCGSmm/TCGSmm.h $
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 1 10/08/13 12:05p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 5 8/09/11 6:28p Fredericko
+// [TAG] EIP66468
+// [Category] Spec Update
+// [Severity] Minor
+// [Description] 1. Changes for Tcg Ppi 1.2 support.
+// [Files] 1 TcgSmm.h
+// 2.TcgSmm.c
+// 3.Tcg_ppi1_2.asl
+// 4. AmiTcgNvflagsSample.c
+// 5. AmiTcgPlatformPeiLib.c
+// 6. AmiTcgPlatformDxe.sdl
+// 7. AmiTcgPlatformDxe.c
+//
+// 4 7/25/11 3:18a Fredericko
+// [TAG] EIP65177
+// [Category] Spec Update
+// [Severity] Minor
+// [Description] TCG Ppi Sec ver 1.2 update
+//
+// 3 8/04/10 5:08p Fredericko
+//
+// 2 5/20/10 8:52a Fredericko
+// Added Header defined switches
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TCGSmm.h
+//
+// Description:
+// Header file for TCGSMM subcomponent
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCGSMM_H_
+#define _TCGSMM_H_
+
+#include <AmiDxeLib.h>
+#include <Protocol\SmmThunk.h>
+#include <Protocol\SmmBase.h>
+#include <Protocol\DevicePath.h>
+#include <Protocol\LoadedImage.h>
+#include <Protocol\SmmSwDispatch.h>
+#include <Token.h>
+#include <AmiDxeLib.h>
+#include <HOB.h>
+#include "..\TCGMisc.h"
+
+
+#define AMI_TCG_PLATFORM_PROTOCOL_GUID\
+ {0x8c939604, 0x700, 0x4415, 0x9d, 0x62, 0x11, 0x61, 0xdb, 0x81, 0x64, 0xa6}
+
+EFI_GUID SwDispatchProtocolGuid = EFI_SMM_SW_DISPATCH_PROTOCOL_GUID;
+EFI_GUID SmmtcgefiOsVariableGuid = AMI_TCG_EFI_OS_VARIABLE_GUID;
+EFI_GUID SmmFlagsStatusguid = AMI_TCG_CONFIRMATION_FLAGS_GUID;
+extern EFI_GUID gEfiSmmBaseProtocolGuid;
+#endif
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2005, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 6145-F Northbelt Pkwy, Norcross, GA 30071 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/TCGSmm/TCGSmm.mak b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.mak
new file mode 100644
index 0000000..37c7464
--- /dev/null
+++ b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.mak
@@ -0,0 +1,101 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+#*************************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Common/TCGSmm/TCGSmm.mak 1 4/21/14 2:18p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:18p $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Common/TCGSmm/TCGSmm.mak $
+#
+# 1 4/21/14 2:18p Fredericko
+#
+# 2 12/10/13 12:57p Fredericko
+#
+# 1 10/08/13 12:05p Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 2 7/11/13 6:12p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20).
+#
+# 1 7/10/13 5:57p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+#
+# 4 12/07/11 4:30p Fredericko
+# [TAG] EIP59683
+# [Category] Improvement
+# [Description] Allow selection between writing to SMI port as a word
+# or as a Byte.
+# Some platforms might require word writes to the SMI Status port.
+# [Files] Tcg.cif, Tcg.sdl, Tcg_ppi1_2_Ex.asl, TcgSmm.mak, TcgSmm.c
+#
+# 3 8/09/10 2:32p Fredericko
+#
+# 2 5/20/10 8:50a Fredericko
+# Included File Header
+# Included File Revision History
+# EIP 37653
+#
+#*************************************************************************
+#<AMI_FHDR_START>
+#
+# Name: TCGSmm.mak
+#
+# Description:
+# Make file for TCG SMM module
+#
+#<AMI_FHDR_END>
+#*************************************************************************
+all : TCGSmm
+
+TCGSmm : $(BUILD_DIR)\TCGSmm.mak TCGSmmBin
+
+$(BUILD_DIR)\TCGSmm.mak : $(TCGSmm_DIR)\TCGSmm.cif $(TCGSmm_DIR)\TCGSmm.mak $(BUILD_RULES)
+ $(CIF2MAK) $(TCGSmm_DIR)\TCGSmm.cif $(CIF2MAK_DEFAULTS)
+
+TcgSmmFlags=$(CFLAGS) \
+ /I$(TCG_DIR)\
+ /I$(TPM12_DIR)\
+ /I$(TCG_DIR)\Common\
+ /I$(PROJECT_DIR)\Include\Protocol\
+
+TCGSmmBin : $(AMIDXELIB) $(AMICSPLib)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TCGSmm.mak all\
+ "CFLAGS=$(TcgSmmFlags) "\
+ "CPFLAGS=$(TcgSmmFlags) "\
+ GUID=FD93F9E1-3C73-46e0-B7B8-2BBA3F718F6C\
+ ENTRY_POINT=TCGSmmInit\
+ TYPE=BS_DRIVER \
+ COMPRESS=1\
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#************************************************************************* \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/TCGSmm/TCGSmm.sdl b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.sdl
new file mode 100644
index 0000000..200ec4f
--- /dev/null
+++ b/Core/EM/TCG2/Common/TCGSmm/TCGSmm.sdl
@@ -0,0 +1,24 @@
+TOKEN
+ Name = "TCGSMM_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable TCGSMM support in Project"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ Master = Yes
+End
+
+PATH
+ Name = "TCGSmm_DIR"
+End
+
+MODULE
+ Help = "Includes TCGSMM.mak to Project"
+ File = "TCGSmm.mak"
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\TCGSmm.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/TcgCRBPei.c b/Core/EM/TCG2/Common/TcgCRBPei.c
new file mode 100644
index 0000000..02dff94
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgCRBPei.c
@@ -0,0 +1,537 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgCRBPei.c 3 4/21/14 3:45p Fredericko $
+//
+// $Revision: 3 $
+//
+// $Date: 4/21/14 3:45p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgCRBPei.c $
+//
+// 3 4/21/14 3:45p Fredericko
+//
+// 2 4/21/14 3:16p Fredericko
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 2 3/17/14 3:17p Fredericko
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 1:55p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name:
+//
+// Description:
+//
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include "TcgCommon.h"
+#include <AmiPeiLib.h>
+#include <Sha.h>
+#include <TcgMisc.h>
+#include <token.h>
+#include <TpmLib.h>
+#include <TcgPc.h>
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+#include "Tpm20CRBLib.h"
+#include "PPI\CpuIo.h"
+#include "PPI\LoadFile.h"
+#include <FFS.h>
+#include "TcgPlatformSetupPeiPolicy.h"
+
+
+//*********************************************************************
+// GLOBAL DEFINITIONS
+//*********************************************************************
+EFI_GUID gEfiCrbPeiAmiTcgLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+EFI_GUID gPeiCrbTcgPpiGuid = PEI_TCG_PPI_GUID;
+
+
+UINT8 GetHashPolicy(IN EFI_PEI_SERVICES **PeiServices);
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: InternalPeiBuildHobGuid
+//
+// Description: Internal abstracted function to create a Hob
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+// IN EFI_GUID *Guid,
+// IN UINTN DataLength,
+// OUT VOID **Hob
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS InternalPeiBuildHobGuid(
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_GUID *Guid,
+ IN UINTN DataLength,
+ OUT VOID **Hob )
+{
+ EFI_STATUS Status;
+
+ Status = (*PeiServices)->CreateHob(
+ PeiServices,
+ EFI_HOB_TYPE_GUID_EXTENSION,
+ (UINT16) ( sizeof (EFI_HOB_GUID_TYPE) + DataLength ),
+ Hob
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ PEI_TRACE((-1, PeiServices, "Hob created \n"));
+ ((EFI_HOB_GUID_TYPE*)(*Hob))->Name = *Guid;
+
+ return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+EFIAPI CrbGetEventLog(
+ IN EFI_PEI_SERVICES **PeiServices,
+ OUT TCG_LOG_HOB **EventLog )
+{
+ EFI_STATUS Status;
+ VOID *HobStart;
+
+ Status = (*PeiServices)->GetHobList( PeiServices, &HobStart );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ return GetNextGuidHob( &HobStart, &gEfiCrbPeiAmiTcgLogHobGuid, EventLog, NULL );
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Name: TcgPeiLogEvent
+//
+// Description: TCGPEI common function to Hash, Log and Extend data
+// using software SHA-1
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *Event,
+// IN *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS
+EFIAPI CrbTcgPeiLogEvent(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCG_PCR_EVENT *Event,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ TCG_LOG_HOB *TcgLog;
+
+
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(Event->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ Status = CrbGetEventLog( PeiServices, &TcgLog );
+ if ( EFI_ERROR( Status ))goto Exit;
+
+ Status = TcgCommonLogEvent(NULL,
+ (TCG_PCR_EVENT*)(TcgLog + 1),
+ &TcgLog->TableSize,
+ TcgLog->TableMaxSize,
+ Event, 0);
+
+ if ( EFI_ERROR( Status ))goto Exit;
+
+ *EventNum = TcgLog->EventNum;
+ TcgLog->EventNum++;
+
+Exit:
+ return Status;
+}
+
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Name: TcgPeiHashLogExtendEventTpm
+//
+// Description: TCGPEI common function to Hash, Log and Extend data using TPM
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *HashData
+// IN HashDataLen
+// IN *NewEvent,
+// IN *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS
+EFIAPI CrbTcgPeiHashLogExtendEventTpm(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN OUT TCG_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum )
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+EFI_STATUS
+CrbTpm20PeiExtend(
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TPM_PCRINDEX PcrIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue )
+{
+ TPM2_PCRExtend_cmd_t Cmd;
+ TPM2_PCRExtend_res_t Res;
+ TPM2_PCRExtend_res_t Tmpres;
+ UINT32 CmdSize;
+ UINT8 *Buffer;
+ UINT8 *AuthSizeOffset;
+ UINT8 *ResultBuf = NULL;
+ UINT32 ResultBufSize = 0;
+ UINT32 DigestSize;
+ EFI_STATUS Status;
+
+ Cmd.Tag = (TPMI_ST_COMMAND_TAG)TPM_H2NS(TPM_ST_SESSIONS);
+ Cmd.CommandSize = TPM_H2NL(sizeof(Cmd));
+ Cmd.CommandCode = TPM_H2NL(TPM_CC_PCR_Extend);
+
+ Buffer = (UINT8 *)&Cmd.inputParameters;
+ *(UINT32 *)Buffer = TPM_H2NL(PcrIndex);
+ Buffer += sizeof(UINT32);
+
+ AuthSizeOffset = Buffer;
+ *(UINT32 *)Buffer = 0;
+ Buffer += sizeof(UINT32);
+
+ // pcr authHandle
+ *(UINT32 *)Buffer = TPM_H2NL(TPM_RS_PW);
+ Buffer += sizeof(UINT32);
+
+ // nonce = nullNonce
+ *(UINT16 *)Buffer = 0;
+ Buffer += sizeof(UINT16);
+
+ // sessionAttributes = 0
+ *(UINT8 *)Buffer = 0;
+ Buffer += sizeof(UINT8);
+
+ // auth = nullAuth
+ *(UINT16 *)Buffer = 0;
+ Buffer += sizeof(UINT16);
+
+ // authorizationSize
+ *(UINT32 *)AuthSizeOffset = TPM_H2NL((UINT32)(Buffer - AuthSizeOffset - sizeof(UINT32)));
+
+ //Digest count
+ *(UINT32 *)Buffer = TPM_H2NL(1);
+ Buffer += sizeof(UINT32);
+
+ //Hash alg
+ // Get the digest size based on Hash Alg
+ if(GetHashPolicy(PeiServices)==0){
+ //Hash alg
+ *(UINT16 *)Buffer = TPM_H2NS(TPM2_ALG_SHA1);
+ Buffer += sizeof(UINT16);
+ DigestSize = 0x14;
+ TcgCommonCopyMem(NULL, Buffer, &Digest->digest, DigestSize);
+ }else{
+ //Hash alg
+ /**(UINT16 *)Buffer = TPM_H2NS(TPM2_ALG_SHA256);
+ Buffer += sizeof(UINT16);
+ DigestSize = 0x20;
+ TcgCommonCopyMem(NULL, Buffer, &Digest->digestSha2, DigestSize);*/
+ return EFI_UNSUPPORTED;
+ }
+
+ Buffer += DigestSize;
+
+ CmdSize = (UINT32)(Buffer - (UINT8 *)&Cmd);
+ Cmd.CommandSize = TPM_H2NL(CmdSize);
+
+ ResultBuf = (UINT8 *) &Tmpres;
+ ResultBufSize = sizeof(Res);
+
+
+ PEI_TRACE((-1, PeiServices, "OutputSizeBefore = %x \n", ResultBufSize));
+
+ Status = CrbSubmitCmd((UINT8 *)&Cmd, CmdSize, ResultBuf, &ResultBufSize);
+
+ PEI_TRACE((-1, PeiServices, "Status = %r \n", Status));
+ PEI_TRACE((-1, PeiServices, "OutputSizeAfter = %x \n", ResultBufSize));
+
+ return Status;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgPeiHashLogExtendEventSW
+// Description: TCGPEI Software function to Hash, Log and Extend data
+// using software SHA-1
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *HashData
+// IN HashDataLen
+// IN OUT *NewEvent,
+// OUT *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS CrbTcgPeiHashLogExtendEventSW(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN OUT TCG_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status;
+ TCG_DIGEST NewPCRValue;
+
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(NewEvent->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ if(GetHashPolicy(PeiServices)==0)
+ {
+ Status = SHA1HashAll( NULL, HashData, HashDataLen, &NewEvent->Digest );
+ if ( EFI_ERROR( Status )){
+ PEI_TRACE((-1, PeiServices, "SHA1HashAll fail %r \n", Status));
+ return Status;
+ }
+ }else if(GetHashPolicy(PeiServices)==1){
+ /* Status = SHA2HashAll( NULL, HashData, HashDataLen, &NewEvent->Digest);
+ if ( EFI_ERROR( Status )){
+ PEI_TRACE((-1, PeiServices, "SHA1HashAll fail %r \n", Status));
+ return Status;
+ }*/
+ }
+
+ Status = CrbTpm20PeiExtend(
+ PeiServices,
+ NewEvent->PCRIndex,
+ &NewEvent->Digest,
+ &NewPCRValue );
+
+ if ( EFI_ERROR( Status )){
+ PEI_TRACE((-1, PeiServices, "CrbTpm20PeiExtend fail %r \n", Status));
+ goto Exit;
+ }
+
+ Status = CrbTcgPeiLogEvent( This, PeiServices, NewEvent, EventNum );
+ PEI_TRACE((-1, PeiServices, "CrbTcgPeiLogEvent fail %r \n", Status));
+
+Exit:
+ return Status;
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgPeiPassThroughToTpm
+//
+// Description: TCGPEI common function to abstract passing commands to the TPM
+// FIFO
+//
+// Input: IN *This
+// IN **PeiServices
+// IN TpmInputParameterBlockSize
+// IN *TpmInputParameterBlock
+// IN TpmOutputParameterBlockSize
+// IN *TpmOutputParameterBlock
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI CrbTcgPeiPassThroughToTpm(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT32 TpmInputParameterBlockSize,
+ IN UINT8 *TpmInputParameterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock )
+{
+ UINT32 Size = 0;
+ EFI_STATUS Status;
+ Size = TpmOutputParameterBlockSize;
+
+ PEI_TRACE((-1, PeiServices, "CrbTcgPeiPassThroughToTpm Execution \n"));
+
+ PEI_TRACE((-1, PeiServices, "OutputSizeBefore = %x \n", Size));
+
+ Status = CrbSubmitCmd(TpmInputParameterBlock,
+ TpmInputParameterBlockSize,
+ TpmOutputParameterBlock,
+ &Size);
+
+ PEI_TRACE((-1, PeiServices, "Status = %r \n", Status));
+ PEI_TRACE((-1, PeiServices, "OutputSizeAfter = %x \n", Size));
+ return Status;
+}
+
+
+static PEI_TCG_PPI mTcgPpi = {
+ CrbTcgPeiHashLogExtendEventSW,
+ CrbTcgPeiLogEvent,
+ CrbTcgPeiPassThroughToTpm
+};
+
+static EFI_PEI_PPI_DESCRIPTOR mTcgPpiList[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiCrbTcgPpiGuid,
+ &mTcgPpi
+ }
+};
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: Tpm20CrbEntry
+//
+// Description:
+//
+//
+// Input:
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI Tpm20CrbEntry(
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ EFI_STATUS Status;
+ TCG_LOG_HOB *TcgLog;
+ EFI_HOB_GUID_TYPE *Hob;
+
+ if(!isTpm20CrbPresent())return EFI_NOT_FOUND;
+ Status = InternalPeiBuildHobGuid(PeiServices, &gEfiCrbPeiAmiTcgLogHobGuid,
+ (sizeof (*TcgLog) + 0x200), & Hob);
+
+ PEI_TRACE((-1, PeiServices, "CrbBuild Hob Status = %r \n", Status));
+
+ TcgLog = (TCG_LOG_HOB*)(Hob + 1);
+ (*PeiServices)->SetMem( TcgLog, sizeof (*TcgLog), 0 );
+ TcgLog->TableMaxSize = 0x200;
+ Status = (*PeiServices)->InstallPpi( PeiServices, mTcgPpiList );
+ return Status;
+}
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/TcgDxe.c b/Core/EM/TCG2/Common/TcgDxe.c
new file mode 100644
index 0000000..84a1e4d
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgDxe.c
@@ -0,0 +1,2187 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TcgDxe.c
+
+ Abstract:
+
+ DXE Driver that provides TCG services
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TcgDxe.c 3 6/14/14 12:28a Fredericko $
+//
+// $Revision: 3 $
+//
+// $Date: 6/14/14 12:28a $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TcgDxe.c $
+//
+// 3 6/14/14 12:28a Fredericko
+//
+// 2 6/09/14 4:50p Fredericko
+// Changes for SetVariable vulnerability during Runtime
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 4 3/17/14 3:19p Fredericko
+//
+// 3 3/14/14 3:22p Fredericko
+//
+// 2 3/11/14 6:37p Fredericko
+// [TAG] EIP151925
+// [Category] New Feature
+// [Description] Changes for TcgGeneric Regression Testing
+//
+// 1 10/08/13 12:03p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 2:00p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 37 10/30/12 11:18a Fredericko
+//
+// 36 10/08/12 10:02a Fredericko
+// [TAG] EIP90986
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] System Hang
+// [RootCause] We tried to measure an unexpected FV if FV_MAIN was not
+// found.
+// [Solution] Verify we found FV_MAIN before trying to measure.
+// [Files] TcgDxe.c
+//
+// 35 5/21/12 11:44a Fredericko
+// Changes for x32 bit build for TCG
+//
+// 34 5/18/12 6:06p Fredericko
+// Type cast size to UINTN for x64 and x32 bit builds
+//
+// 33 5/09/12 6:37p Fredericko
+// Tcm changes. For Win Server 8 and reboot test failure.
+//
+// 32 4/28/12 3:26p Fredericko
+// If PPI request comes in and VGA and USB enumeration is disabled Ppi
+// request cannot be dispalyed or executed. So Abort Fastboot when Ppi
+// request comes in.
+//
+// 31 4/27/12 6:06p Fredericko
+// Measurement of FWVol Changed.
+//
+// 30 3/19/12 6:30p Fredericko
+// [TAG] EIP82769
+// [Category] Improvement
+// [Description] Firmware updates disable the TPM when Firmware update
+// is done
+// Changes for Tcg Performance Metrics Improvement.
+// [Files] EIP82769: xTcgPei.c, TcgDxe.c, xTcgDxe,c
+// Performance: Files Changed: Tcg.sdl, TcgMisc.h, TcgDxe.c, TcgCommon.c,
+// TcgCommon.h,
+// AmiTcgPlatformPeiLib.c, AmiTcgPlatformDxe.c, TcgDxe.dxs
+//
+// 29 2/03/12 5:17p Fredericko
+// [TAG] EIP81665
+// [Category] Improvement
+// [Description] Support for MOR feature improvement
+// [Files] Tcg.sdl, AmiTcgPlatformDxe.c, Tcgdxe.c, Tcglegacy.c
+//
+// 28 11/14/11 1:31p Fredericko
+// Changes for Tcgprotocol interface. Function is currently not used.
+//
+// 27 8/26/11 1:07p Fredericko
+// Fastboot Changes.
+//
+// 26 8/09/11 6:16p Fredericko
+// [TAG] EIP66465
+// [Category] Improvement
+// [Description] 1. Added support to remove EFI_EV_ACTION from the TCG
+// logs if customer wants.
+// [Files] 1. Tcgdxe.c
+// 2. Tcgpei.c
+// 3. Tcg.sdl
+//
+// 25 4/22/11 8:51p Fredericko
+// Changes for build in x32 bit mode.
+//
+// 24 4/04/11 1:58p Fredericko
+// Removed #pragma optimization directives
+//
+// 23 4/01/11 9:37a Fredericko
+// Updated function Header
+//
+// 22 3/29/11 1:12p Fredericko
+//
+// 21 3/28/11 2:19p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 20 5/19/10 5:36p Fredericko
+// Included File Header
+// Included File Revision History
+// Updated AMI Function Headers
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgDxe.c
+//
+// Description:
+// Abstracted functions for Tcg protocol are defined here
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include "TcgCommon.h"
+#include <sha.h>
+#include <TcgMisc.h>
+#include <Token.h>
+#include <AmiDxeLib.h>
+#include <Runtime.h>
+#include <AmiPeiLib.h>
+#include "protocol\TcgService\TcgTcmService.h"
+#include "TcgPlatformSetupPolicy.h"
+#include <AcpiSupport.h>
+#include "TcgPc.h"
+#include "protocol\TcgService\TcgService.h"
+#include "protocol\TpmDevice\TpmDevice.h"
+
+#if PI_SPECIFICATION_VERSION<0x00010000
+#include <Protocol\FirmwareVolume.h>
+#else
+#include <Protocol\FirmwareVolume2.h>
+#endif
+
+
+EFI_GUID gEfiAmiDTcgLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+
+UINT8 GetHashPolicy();
+
+#pragma pack (1)
+typedef struct
+{
+ EFI_PHYSICAL_ADDRESS PostCodeAddress;
+ #if x64_BUILD
+ UINT64 PostCodeLength;
+ #else
+ UINTN PostCodeLength;
+ #endif
+} EFI_TCG_EV_POST_CODE;
+
+typedef struct
+{
+ EFI_TCG_PCR_EVENT_HEADER Header;
+ EFI_TCG_EV_POST_CODE Event;
+} PEI_EFI_POST_CODE;
+
+#pragma pack()
+
+
+typedef struct _TCG_DXE_PRIVATE_DATA
+{
+ EFI_TCG_PROTOCOL TcgServiceProtocol;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+} TCG_DXE_PRIVATE_DATA;
+
+
+typedef struct _TCM_DXE_PRIVATE_DATA
+{
+ EFI_TCM_PROTOCOL TcgServiceProtocol;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+} TCM_DXE_PRIVATE_DATA;
+
+
+
+EFI_STATUS EFIAPI TcgDxeLogEvent (
+ IN EFI_TCG_PROTOCOL *This,
+ IN TCG_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ IN UINT32 Flags );
+
+EFI_STATUS EFIAPI TcmDxeLogEvent(
+ IN EFI_TCM_PROTOCOL *This,
+ IN TCM_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ IN UINT32 Flags );
+
+EFI_STATUS
+__stdcall Tcg20CommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PcrIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue,
+ IN UINT8 DigestSize );
+
+BOOLEAN IsTpm20Device();
+UINTN FindNextLogLocation(TCG_PCR_EVENT_HDR *TcgLog, UINTN EventNum);
+
+EFI_GUID gEfiTcgCapHobGuid = EFI_TCG_CAP_HOB_GUID;
+static UINTN TcmBootVar = 0;
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmBootDone
+//
+// Description: SetEfiOSTransitions
+//
+// Input: IN EFI_EVENT efiev
+// IN VOID *ctx
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+void TcmBootDone(
+ IN EFI_EVENT efiev,
+ IN VOID *ctx )
+{
+ TcmBootVar = 1;
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EfiOSReadyToBoot
+//
+// Description: Sets ready to boot callback on ready to boot
+//
+// Input: NONE
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcmOSTransition()
+{
+ EFI_EVENT ReadToBootEvent;
+ EFI_STATUS Status;
+
+ #if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT)\
+ && EFI_SPECIFICATION_VERSION < 0x20000
+
+ Status = pBS->CreateEvent( EFI_EVENT_SIGNAL_READY_TO_BOOT,
+ EFI_TPL_CALLBACK,
+ TcmBootDone, NULL, &ReadToBootEvent );
+
+ #else
+ Status = CreateReadyToBootEvent( EFI_TPL_CALLBACK,
+ TcmBootDone,
+ NULL,
+ &ReadToBootEvent );
+ #endif
+
+ return Status;
+}
+
+
+#define _CR( Record, TYPE,\
+ Field )((TYPE*) ((CHAR8*) (Record) - (CHAR8*) &(((TYPE*) 0)->Field)))
+
+#define TCG_DXE_PRIVATE_DATA_FROM_THIS( This ) \
+ _CR( This, TCG_DXE_PRIVATE_DATA, TcgServiceProtocol )
+
+#define TCM_DXE_PRIVATE_DATA_FROM_THIS( This ) \
+ _CR( This, TCM_DXE_PRIVATE_DATA, TcgServiceProtocol )
+
+
+TCG_ACPI_TABLE mTcgAcpiTableTemplate = {
+ {
+ EFI_ACPI_3_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE,
+ sizeof (TCG_ACPI_TABLE)
+ //
+ // Compiler initializes the remaining bytes to 0
+ // These fields should be filled in in production
+ //
+ },
+ 0,
+ TPM_LOG_AREA_MAX_LEN,
+ (EFI_PHYSICAL_ADDRESS)( -1 )
+};
+
+static TPM_Capabilities_PermanentFlag TcgDxe_Cap;
+
+EFI_STATUS
+__stdcall TcgCommonPassThrough(
+ IN VOID *Context,
+ IN UINT32 NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINT32 NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers )
+{
+ TCG_DXE_PRIVATE_DATA *Private;
+ EFI_STATUS Status;
+
+ Private = TCG_DXE_PRIVATE_DATA_FROM_THIS( Context );
+
+ Status = Private->TpmDevice->Init( Private->TpmDevice );
+
+ TRACE(( TRACE_ALWAYS,"TcgDxePassThroughToTpm Init Status = %r \n", Status));
+
+ Status= Private->TpmDevice->Transmit(
+ Private->TpmDevice,
+ NoInputBuffers,
+ InputBuffers,
+ NoOutputBuffers,
+ OutputBuffers
+ );
+
+ TRACE(( TRACE_ALWAYS,"TcgDxePassThroughToTpm Transmit Status = %r \n", Status));
+
+ Private->TpmDevice->Close( Private->TpmDevice );
+
+ return Status;
+
+}
+
+
+EFI_STATUS EFIAPI TcgDxePassThroughToTpm(
+ IN EFI_TCG_PROTOCOL *This,
+ IN UINT32 TpmInputParamterBlockSize,
+ IN UINT8 *TpmInputParamterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock )
+{
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+ EFI_STATUS Status;
+ TCG_DXE_PRIVATE_DATA *Private;
+
+ //some applications might not set init command before making this call.
+ //Just set init commands[locality zero for them]
+ Private = TCG_DXE_PRIVATE_DATA_FROM_THIS( This );
+ Status = Private->TpmDevice->Init( Private->TpmDevice );
+
+ TRACE(( TRACE_ALWAYS,"TcgDxePassThroughToTpm Init Status = %r \n", Status));
+
+ InBuffer[0].Buffer = TpmInputParamterBlock;
+ InBuffer[0].Size = TpmInputParamterBlockSize;
+ OutBuffer[0].Buffer = TpmOutputParameterBlock;
+ OutBuffer[0].Size = TpmOutputParameterBlockSize;
+
+ Status= Private->TpmDevice->Transmit(
+ Private->TpmDevice,
+ sizeof (InBuffer) / sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer);
+
+ TRACE(( TRACE_ALWAYS,"TcgDxePassThroughToTpm Transmit Status = %r \n", Status));
+
+ Private->TpmDevice->Close( Private->TpmDevice );
+
+ TRACE(( TRACE_ALWAYS,"TcgDxePassThroughToTpm Close Status = %r \n", Status));
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+__stdcall TcgDxeCommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PCRIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue )
+{
+ TPM_1_2_CMD_HEADER cmdHeader;
+ TPM_1_2_RET_HEADER retHeader;
+ TPM_TRANSMIT_BUFFER InBuffer[3], OutBuffer[2];
+ BOOLEAN Sha2 = TRUE;
+
+ if(IsTpm20Device()){
+ TRACE(( TRACE_ALWAYS,"Tpm20 Extend Status \n"));
+
+ if(GetHashPolicy()==0){
+ return(Tcg20CommonExtend(NULL, PCRIndex, Digest, NewPCRValue, 20));
+ }else{
+ return(Tcg20CommonExtend((VOID *)&Sha2, PCRIndex, Digest, NewPCRValue,32));
+ }
+ }
+
+ TRACE(( TRACE_ALWAYS,"Tpm1_2 Extend Status \n"));
+ InBuffer[0].Buffer = &cmdHeader;
+ InBuffer[0].Size = sizeof (cmdHeader);
+ InBuffer[1].Buffer = &PCRIndex;
+ InBuffer[1].Size = sizeof (PCRIndex);
+ InBuffer[2].Buffer = Digest->digest;
+ InBuffer[2].Size = sizeof (Digest->digest);
+
+ OutBuffer[0].Buffer = &retHeader;
+ OutBuffer[0].Size = sizeof (retHeader);
+ OutBuffer[1].Buffer = NewPCRValue->digest;
+ OutBuffer[1].Size = sizeof (NewPCRValue->digest);
+
+ cmdHeader.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdHeader.ParamSize = TPM_H2NL(sizeof (cmdHeader)
+ + sizeof (PCRIndex) + sizeof (Digest->digest));
+
+ cmdHeader.Ordinal = TPM_H2NL( TPM_ORD_Extend );
+ PCRIndex = TcgCommonH2NL( PCRIndex );
+
+ return TcgCommonPassThrough( CallbackContext,
+ sizeof (InBuffer) / sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer);
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmCommonPassThrough
+//
+// Description: Helper function for TCM transmit command
+//
+// Input: VOID *Context
+// UINT32 NoInputBuffers
+// TPM_TRANSMIT_BUFFER InputBuffers
+// UINT32 NoOutputBuffers
+// TPM_TRANSMIT_BUFFER OutputBuffers
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+__stdcall TcmCommonPassThrough(
+ IN VOID *Context,
+ IN UINT32 NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINT32 NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers )
+{
+ TCM_DXE_PRIVATE_DATA *Private;
+
+ Private = TCM_DXE_PRIVATE_DATA_FROM_THIS( Context );
+ return Private->TpmDevice->Transmit(
+ Private->TpmDevice,
+ NoInputBuffers,
+ InputBuffers,
+ NoOutputBuffers,
+ OutputBuffers
+ );
+}
+
+
+EFI_STATUS EFIAPI TcgDxeStatusCheck(
+ IN EFI_TCG_PROTOCOL *This,
+ OUT TCG_EFI_BOOT_SERVICE_CAPABILITY *ProtocolCapability,
+ OUT UINT32 *TCGFeatureFlags,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLocation,
+ OUT EFI_PHYSICAL_ADDRESS *LastEvent )
+{
+ TCG_LOG_HOB *TcgLog;
+ TCG_PCR_EVENT *EventStart;
+ UINTN Index;
+
+ if ( ProtocolCapability != NULL )
+ {
+ pBS->SetMem( ProtocolCapability, sizeof (*ProtocolCapability), 0 );
+ ProtocolCapability->Size = sizeof (TCG_EFI_BOOT_SERVICE_CAPABILITY);
+ ProtocolCapability->StructureVersion.Major = TCG_SPEC_VERSION_MAJOR;
+ ProtocolCapability->StructureVersion.Minor = TCG_SPEC_VERSION_MINOR;
+ ProtocolCapability->StructureVersion.RevMajor = 0;
+ ProtocolCapability->StructureVersion.RevMinor = 0;
+ ProtocolCapability->ProtocolSpecVersion.Major = TCG_SPEC_VERSION_MAJOR;
+ ProtocolCapability->ProtocolSpecVersion.Minor = TCG_SPEC_VERSION_MINOR;
+ ProtocolCapability->ProtocolSpecVersion.RevMajor = 0;
+ ProtocolCapability->ProtocolSpecVersion.RevMinor = 0;
+ ProtocolCapability->HashAlgorithmBitmap = 1; // SHA-1
+ ProtocolCapability->TPMPresentFlag = 1; // TPM is present.
+ ProtocolCapability->TPMDeactivatedFlag = TcgDxe_Cap.deactivated;
+ }
+
+ if ( TCGFeatureFlags != NULL )
+ {
+ *TCGFeatureFlags = 0;
+ }
+
+ EventStart = (TCG_PCR_EVENT*)(UINTN)mTcgAcpiTableTemplate.LogStart;
+ TcgLog = (TCG_LOG_HOB*)EventStart;
+ TcgLog--;
+
+
+ if ( EventLogLocation != NULL )
+ {
+ *EventLogLocation
+ = (EFI_PHYSICAL_ADDRESS)( UINTN ) mTcgAcpiTableTemplate.LogStart;
+ }
+
+ if ( LastEvent != NULL )
+ {
+ if ( TcgLog->EventNum == 0 )
+ {
+ *LastEvent = 0;
+ }
+ else {
+ Index = TcgLog->EventNum;
+ *LastEvent = (EFI_PHYSICAL_ADDRESS)( UINTN )FindNextLogLocation((TCG_PCR_EVENT_HDR *)mTcgAcpiTableTemplate.LogStart,
+ (TcgLog->EventNum - 1));
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgTcmDxeStatusCheck
+//
+// Description: Tcm Dxe status check function
+//
+// Input: IN EFI_TCM_PROTOCOL *This,
+// OUT TCM_EFI_BOOT_SERVICE_CAPABILITY *ProtocolCapability,
+// OUT UINT32 *TCGFeatureFlags,
+// OUT EFI_PHYSICAL_ADDRESS *EventLogLocation,
+// OUT EFI_PHYSICAL_ADDRESS *LastEvent
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS EFIAPI TcgTcmDxeStatusCheck(
+ IN EFI_TCM_PROTOCOL *This,
+ OUT TCM_EFI_BOOT_SERVICE_CAPABILITY *ProtocolCapability,
+ OUT UINT32 *TCGFeatureFlags,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLocation,
+ OUT EFI_PHYSICAL_ADDRESS *LastEvent )
+{
+ TCG_LOG_HOB *TcgLog;
+ TCM_PCR_EVENT *EventStart;
+ UINTN Index;
+
+ if((AutoSupportType()) && (TcmBootVar == 1)){
+ pBS->SetMem( ProtocolCapability, sizeof (TCM_EFI_BOOT_SERVICE_CAPABILITY), 0 );
+ if ( TCGFeatureFlags != NULL )*TCGFeatureFlags = 0;
+ if ( LastEvent != NULL )*LastEvent = 0;
+ return EFI_UNSUPPORTED;
+ }
+
+ if ( ProtocolCapability != NULL )
+ {
+ pBS->SetMem( ProtocolCapability, sizeof (*ProtocolCapability), 0 );
+ ProtocolCapability->Size = sizeof (TCG_EFI_BOOT_SERVICE_CAPABILITY);
+ ProtocolCapability->StructureVersion.Major = TCG_SPEC_VERSION_MAJOR;
+ ProtocolCapability->StructureVersion.Minor = TCG_SPEC_VERSION_MINOR;
+ ProtocolCapability->StructureVersion.RevMajor = 0;
+ ProtocolCapability->StructureVersion.RevMinor = 0;
+ ProtocolCapability->ProtocolSpecVersion.Major = TCG_SPEC_VERSION_MAJOR;
+ ProtocolCapability->ProtocolSpecVersion.Minor = TCG_SPEC_VERSION_MINOR;
+ ProtocolCapability->ProtocolSpecVersion.RevMajor = 0;
+ ProtocolCapability->ProtocolSpecVersion.RevMinor = 0;
+ ProtocolCapability->HashAlgorithmBitmap = 1; // SHA-1
+ ProtocolCapability->TPMPresentFlag = 1; // TPM is present.
+ ProtocolCapability->TPMDeactivatedFlag = TcgDxe_Cap.deactivated;
+ }
+
+ if ( TCGFeatureFlags != NULL )
+ {
+ *TCGFeatureFlags = 0;
+ }
+
+ EventStart = (TCM_PCR_EVENT*)(UINTN)mTcgAcpiTableTemplate.LogStart;
+ TcgLog = (TCG_LOG_HOB*)EventStart;
+ TcgLog--;
+
+ if ( EventLogLocation != NULL )
+ {
+ *EventLogLocation
+ = (EFI_PHYSICAL_ADDRESS)( UINTN ) mTcgAcpiTableTemplate.LogStart;
+ }
+
+ if ( LastEvent != NULL )
+ {
+ if ( TcgLog->EventNum == 0 )
+ {
+ *LastEvent = 0;
+ }
+ else {
+ Index = TcgLog->EventNum;
+
+ do
+ {
+ *LastEvent = (EFI_PHYSICAL_ADDRESS)( UINTN ) EventStart;
+ EventStart = (TCM_PCR_EVENT*)(UINTN)(
+ *LastEvent
+ + _TPM_STRUCT_PARTIAL_SIZE( TCM_PCR_EVENT, Event[ 0] )
+ + EventStart->EventSize
+ );
+ } while ( --Index > 0 );
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+
+
+
+
+EFI_STATUS EFIAPI TcgDxeHashAll(
+ IN EFI_TCG_PROTOCOL *This,
+ IN UINT8 *HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT UINT64 *HashedDataLen,
+ IN OUT UINT8 **HashedDataResult )
+{
+ if ( AlgorithmId != TCG_ALG_SHA )
+ {
+ return EFI_UNSUPPORTED;
+ }
+
+ if ( *HashedDataResult == NULL || *HashedDataLen == 0 )
+ {
+ *HashedDataLen = sizeof (TCG_DIGEST);
+ pBS->AllocatePool( EfiBootServicesData,
+ (UINTN)*HashedDataLen,
+ HashedDataResult );
+
+ if ( *HashedDataResult == NULL )
+ {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ }
+
+ return SHA1HashAll(
+ This,
+ (VOID*)(UINTN)HashData,
+ (UINTN)HashDataLen,
+ (TCG_DIGEST*)*HashedDataResult);
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmDxeHashAll
+//
+// Description: TcmDxeHashAll function [SHA1]
+//
+// Input: IN EFI_TCG_PROTOCOL *This,
+// IN UINT8 *HashData,
+// IN UINT64 HashDataLen,
+// IN TCG_ALGORITHM_ID AlgorithmId,
+// IN OUT UINT64 *HashedDataLen,
+// IN OUT UINT8 **HashedDataResult
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS EFIAPI TcmDxeHashAll(
+ IN EFI_TCM_PROTOCOL *This,
+ IN UINT8 *HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT UINT64 *HashedDataLen,
+ IN OUT UINT8 **HashedDataResult )
+{
+
+ if((AutoSupportType()) && (TcmBootVar == 1)){
+ return EFI_UNSUPPORTED;
+ }
+
+ if ( AlgorithmId != TCG_ALG_SHA )
+ {
+ return EFI_UNSUPPORTED;
+ }
+
+ if ( *HashedDataResult == NULL || *HashedDataLen == 0 )
+ {
+ *HashedDataLen = sizeof (TCG_DIGEST);
+ pBS->AllocatePool( EfiBootServicesData,
+ (UINTN)*HashedDataLen,
+ HashedDataResult );
+
+ if ( *HashedDataResult == NULL )
+ {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ }
+
+ return SHA1HashAll(
+ This,
+ (VOID*)(UINTN)HashData,
+ (UINTN)HashDataLen,
+ (TCG_DIGEST*)*HashedDataResult);
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgDxeHashLogExtendEventTpm
+//
+// Description: TcgDxe common function to Hash, Log and Extend data using TPM
+//
+// Input: *This
+// *HashData
+// HashDataLen
+// AlgorithmId,
+// *TCGLogData,
+// *EventNum,
+// *EventLogLastEntry
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals: TcgCommonSha1Start, TcgCommonSha1Start, TcgCommonSha1CompleteExtend
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgDxeHashLogExtendEventTpm(
+ IN EFI_TCG_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT TCG_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNum,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry )
+{
+ EFI_STATUS Status;
+ UINT32 Sha1MaxBytes;
+ TCG_DIGEST NewPCRValue;
+ TCG_DXE_PRIVATE_DATA *Private;
+
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(TCGLogData->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ Private = TCG_DXE_PRIVATE_DATA_FROM_THIS( This );
+
+ Status = Private->TpmDevice->Init( Private->TpmDevice );
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE(( TRACE_ALWAYS,"Private->TpmDevice Status = %r \n", Status));
+ goto Exit;
+ }
+
+ Status = TcgCommonSha1Start( This, TCG_ALG_SHA, &Sha1MaxBytes );
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE(( TRACE_ALWAYS,"TcgCommonSha1Start Status = %r \n", Status));
+ goto Exit;
+ }
+
+ Status = TcgCommonSha1Update(
+ This,
+ (UINT8 *)HashData,
+ (UINT32)HashDataLen,
+ Sha1MaxBytes
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE(( TRACE_ALWAYS,"TcgCommonSha1Update Status = %r \n", Status));
+ goto Exit;
+ }
+
+#if defined(TCG_DEBUG_MODE) && (TCG_DEBUG_MODE == 1)
+ HashData += (UINTN)(HashDataLen & ~63);
+ HashDataLen &= 63;
+#else
+ HashData += (HashDataLen & ~63);
+ HashDataLen &= 63;
+#endif
+
+ Status = TcgCommonSha1CompleteExtend(
+ This,
+ (UINT8 *)HashData,
+ (UINT32)HashDataLen,
+ TCGLogData->PCRIndex,
+ &TCGLogData->Digest,
+ &NewPCRValue
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE(( TRACE_ALWAYS,"TcgCommonSha1CompleteExtend Status = %r \n", Status));
+ goto Exit;
+ }
+
+ Status = TcgDxeLogEvent( This, TCGLogData, EventNum, 1 );
+ TRACE(( TRACE_ALWAYS,"TcgDxeLogEvent Status = %r \n", Status));
+
+Exit:
+ Private->TpmDevice->Close( Private->TpmDevice );
+ return Status;
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgDxeHashLogExtendEventTcm
+//
+// Description: TcgDxe common function to Hash, Log and Extend data using TPM
+//
+// Input: *This
+// *HashData
+// HashDataLen
+// AlgorithmId,
+// *TCGLogData,
+// *EventNum,
+// *EventLogLastEntry
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals: TcgCommonSha1Start, TcgCommonSha1Start, TcgCommonSha1CompleteExtend
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgDxeHashLogExtendEventTcm(
+ IN EFI_TCM_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT TCM_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNum,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry )
+{
+ EFI_STATUS Status;
+ UINT32 Sha1MaxBytes;
+ TCM_DIGEST NewPCRValue;
+ TCM_DXE_PRIVATE_DATA *Private;
+
+ Private = TCM_DXE_PRIVATE_DATA_FROM_THIS( This );
+
+ if((AutoSupportType()) && (TcmBootVar == 1)){
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = TcgCommonSha1Start( This, TCG_ALG_SHA, &Sha1MaxBytes );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgCommonSha1Update(
+ This,
+ (UINT8 *)HashData,
+ (UINT32)HashDataLen,
+ Sha1MaxBytes
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ HashData += (HashDataLen & ~63);
+ HashDataLen &= 63;
+
+ Status = TcmCommonSha1CompleteExtend(
+ This,
+ (UINT8 *)HashData,
+ (UINT32)HashDataLen,
+ TCGLogData->PCRIndex,
+ &TCGLogData->Digest,
+ &NewPCRValue
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcmDxeLogEvent( This, TCGLogData, EventNum, 1 );
+
+Exit:
+ return Status;
+}
+
+#pragma optimize("",off)
+
+VOID
+EFIAPI
+PrintBuffer(IN UINT8 *Buffer, IN UINT32 BufferSize)
+{
+ UINT32 Index;
+
+ TRACE(( TRACE_ALWAYS, "Buffer Address: 0x%08x, Size: 0x%08x, Value:\n", Buffer, BufferSize));
+ for(Index = 0; Index < BufferSize; Index++){
+ TRACE(( TRACE_ALWAYS, "%02x ", *(Buffer + Index)));
+ if((Index+1) % 16 == 0) TRACE(( TRACE_ALWAYS, "\n"));
+ }
+ TRACE(( TRACE_ALWAYS, "\n"));
+}
+
+
+EFI_STATUS
+__stdcall TcgDxeCommonLogEvent(
+ IN VOID *CallbackContext,
+ IN TCG_PCR_EVENT *EvtLog,
+ IN OUT UINT32 *TableSize,
+ IN UINT32 MaxSize,
+ IN TCG_PCR_EVENT *NewEntry,
+ IN UINT8 HashAlgorithm )
+{
+ UINT32 TempSize;
+
+ //protect Tcglog from possible overflow log operation
+ if(NewEntry->EventSize > ((UINT32)(~0) - sizeof(EFI_TCG_PCR_EVENT_HEADER))){
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ TempSize = sizeof(TCG_PCR_EVENT)-sizeof(NewEntry->Digest) - sizeof(UINT32)-1;
+
+ TcgCommonCopyMem( CallbackContext, EvtLog, NewEntry, TempSize );
+
+ PrintBuffer((UINT8 *)NewEntry, 0x50);
+
+ TRACE(( TRACE_ALWAYS,"CopyMem 1 \n"));
+
+ if(HashAlgorithm == 0){
+ TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), (UINT8 *)&NewEntry->Digest.digest, sizeof(NewEntry->Digest.digest) );
+ TempSize+=sizeof(NewEntry->Digest.digest);
+ TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), (UINT8 *)&NewEntry->EventSize, sizeof(UINT32));
+ TempSize+=sizeof(UINT32);
+ TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), NewEntry->Event, NewEntry->EventSize);
+ }else{
+ /*TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), (UINT8 *)&NewEntry->Digest.digestSha2, sizeof(NewEntry->Digest.digestSha2) );
+ TempSize+=sizeof(NewEntry->Digest.digestSha2);
+ TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), (UINT8 *)&NewEntry->EventSize, sizeof(UINT32));
+ TempSize+=sizeof(UINT32);
+ TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), NewEntry->Event, NewEntry->EventSize);
+ */
+ }
+
+ *TableSize += (TempSize + NewEntry->EventSize);
+ return EFI_SUCCESS;
+}
+#pragma optimize("",on)
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgDxeLogEvent
+//
+// Description: Logs TCG events in DXE
+//
+// Input: IN EFI_TCG_PROTOCOL *This,
+// IN TCG_PCR_EVENT *TCGLogData,
+// IN OUT UINT32 *EventNumber,
+// IN UINT32 Flags
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+#pragma optimize("",off)
+EFI_STATUS EFIAPI TcgDxeLogEvent(
+ IN EFI_TCG_PROTOCOL *This,
+ IN TCG_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ IN UINT32 Flags )
+{
+ EFI_STATUS Status;
+ TCG_LOG_HOB *TcgLog;
+ TCG_DXE_PRIVATE_DATA *Private;
+ TCG_DIGEST NewPCR;
+ UINTN NextLocation;
+ UINT8 HashAlgo = GetHashPolicy();
+
+
+ Private = TCG_DXE_PRIVATE_DATA_FROM_THIS( This );
+
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(TCGLogData->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ Status = EFI_SUCCESS;
+
+ if ( !(Flags & (UINT32)(0x1)))
+ {
+ TRACE((TRACE_ALWAYS, "Flags = %x \n", Flags));
+ Status = Private->TpmDevice->Init( Private->TpmDevice );
+
+ TRACE((TRACE_ALWAYS, "Private->TpmDevice->Init = %r \n", Status));
+
+ if ( !EFI_ERROR( Status ))
+ {
+ Status = TcgDxeCommonExtend(
+ This,
+ TCGLogData->PCRIndex,
+ &TCGLogData->Digest,
+ &NewPCR
+ );
+
+ TRACE((TRACE_ALWAYS, "TcgDxeCommonExtend Status = %r \n", Status));
+ }
+ Private->TpmDevice->Close( Private->TpmDevice );
+ }
+
+ if ( !TcgDxe_Cap.deactivated )
+ {
+ TcgLog = (TCG_LOG_HOB*)(UINTN)mTcgAcpiTableTemplate.LogStart;
+ TcgLog--;
+
+ if ( !EFI_ERROR( Status ))
+ {
+ NextLocation = FindNextLogLocation((TCG_PCR_EVENT_HDR*)(TcgLog + 1), TcgLog->EventNum);
+
+ Status = TcgDxeCommonLogEvent(
+ This,
+ (TCG_PCR_EVENT*)(NextLocation),
+ &TcgLog->TableSize,
+ TcgLog->TableMaxSize,
+ TCGLogData, HashAlgo);
+
+
+ if ( !EFI_ERROR( Status ))
+ {
+ TcgLog->EventNum++;
+ *EventNumber = TcgLog->EventNum;
+ }
+ }
+ }
+ return Status;
+}
+#pragma optimize("",on)
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmDxeLogEvent
+//
+// Description: Logs TCM events in DXE
+//
+// Input: IN EFI_TCG_PROTOCOL *This,
+// IN TCG_PCR_EVENT *TCGLogData,
+// IN OUT UINT32 *EventNumber,
+// IN UINT32 Flags
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS EFIAPI TcmDxeLogEvent(
+ IN EFI_TCM_PROTOCOL *This,
+ IN TCM_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ IN UINT32 Flags )
+{
+ EFI_STATUS Status;
+ TCG_LOG_HOB *TcgLog;
+ TCM_DXE_PRIVATE_DATA *Private;
+ TCM_DIGEST NewPCR;
+
+ Private = TCM_DXE_PRIVATE_DATA_FROM_THIS( This );
+
+ if((AutoSupportType()) && (TcmBootVar == 1)){
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = EFI_SUCCESS;
+
+ if ( !(Flags & 1))
+ {
+ if ( !EFI_ERROR( Status ))
+ {
+ Status = TcmCommonExtend(
+ This,
+ TCGLogData->PCRIndex,
+ &TCGLogData->Digest,
+ &NewPCR);
+ }
+ }
+
+ if ( !TcgDxe_Cap.deactivated )
+ {
+ TcgLog = (TCG_LOG_HOB*)(UINTN)mTcgAcpiTableTemplate.LogStart;
+ TcgLog--;
+
+ if ( !EFI_ERROR( Status ))
+ {
+ Status = TcmCommonLogEvent(
+ This,
+ (TCM_PCR_EVENT*)(TcgLog + 1),
+ &TcgLog->TableSize,
+ TcgLog->TableMaxSize,
+ TCGLogData
+ );
+
+ if ( !EFI_ERROR( Status ))
+ {
+ TcgLog->EventNum++;
+ *EventNumber = TcgLog->EventNum;
+ }
+ }
+ }
+ return Status;
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgDxePassThroughToTcm
+//
+// Description: Helper function for TCM transmit function
+//
+// Input: IN EFI_TCM_PROTOCOL *This,
+// IN UINT32 TpmInputParamterBlockSize,
+// IN UINT8 *TpmInputParamterBlock,
+// IN UINT32 TpmOutputParameterBlockSize,
+// IN UINT8 *TpmOutputParameterBlock
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS EFIAPI TcgDxePassThroughToTcm(
+ IN EFI_TCM_PROTOCOL *This,
+ IN UINT32 TpmInputParamterBlockSize,
+ IN UINT8 *TpmInputParamterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock )
+{
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+ EFI_STATUS Status;
+ TCM_DXE_PRIVATE_DATA *Private;
+
+ //some applications might not set init command before making this call.
+ //Just set init commands[locality zero for them]
+ Private = TCM_DXE_PRIVATE_DATA_FROM_THIS( This );
+
+ if((AutoSupportType()) && (TcmBootVar == 1)){
+ return EFI_UNSUPPORTED;
+ }
+
+ InBuffer[0].Buffer = TpmInputParamterBlock;
+ InBuffer[0].Size = TpmInputParamterBlockSize;
+ OutBuffer[0].Buffer = TpmOutputParameterBlock;
+ OutBuffer[0].Size = TpmOutputParameterBlockSize;
+
+ Status = TcmCommonPassThrough(
+ This,
+ sizeof (InBuffer) / sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer
+ );
+
+ return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS EFIAPI TcgDxeHashLogExtendEvent(
+ IN EFI_TCG_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT TCG_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *EventNumber,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry )
+{
+ EFI_STATUS Status;
+ UINT64 DigestSize;
+ UINT8 *HashResult;
+ TCG_DXE_PRIVATE_DATA *Private;
+
+ Private = TCG_DXE_PRIVATE_DATA_FROM_THIS( This );
+
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(TCGLogData->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ DigestSize = sizeof (TCGLogData->Digest);
+ HashResult = TCGLogData->Digest.digest;
+ Status = TcgDxeHashAll(
+ This,
+ (UINT8 *)HashData,
+ HashDataLen,
+ AlgorithmId,
+ &DigestSize,
+ &HashResult
+ );
+
+ TRACE((TRACE_ALWAYS, "TcgDxeHashAll Status = %r \n", Status));
+
+
+ if ( !EFI_ERROR( Status ))
+ {
+ Status = TcgDxeLogEvent(
+ This,
+ TCGLogData,
+ EventNumber,
+ 0
+ );
+
+ TRACE((TRACE_ALWAYS, "TcgDxeLogEvent Status = %r \n", Status));
+ }
+
+ return Status;
+}
+
+
+static TCG_DXE_PRIVATE_DATA mTcgDxeData = {
+ {
+ TcgDxeStatusCheck,
+ TcgDxeHashAll,
+ TcgDxeLogEvent,
+ TcgDxePassThroughToTpm,
+ TcgDxeHashLogExtendEvent
+ },
+ NULL
+};
+
+
+static TCM_DXE_PRIVATE_DATA mTcmDxeData = {
+ {
+ TcgTcmDxeStatusCheck,
+ TcmDxeHashAll,
+ TcmDxeLogEvent,
+ TcgDxePassThroughToTcm,
+ TcgDxeHashLogExtendEventTcm
+ },
+ NULL
+};
+
+//***********************************************************************
+// MOR RELATED FUNCTIONS
+//***********************************************************************
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: OverwriteSystemMemory
+//
+// Description: Overwrites system memory
+//
+// Input:
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS OverwriteSystemMemory(
+)
+{
+
+ EFI_STATUS Status;
+ UINT8 TmpMemoryMap[1];
+ UINTN MapKey;
+ UINTN DescriptorSize;
+ UINT32 DescriptorVersion;
+ UINTN MemoryMapSize;
+ EFI_MEMORY_DESCRIPTOR *MemoryMap;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;
+ BOOLEAN IsRuntime;
+ UINTN Index;
+ UINT64 Size;
+ IsRuntime = FALSE;
+
+ //
+ // Get System MemoryMapSize
+ //
+ MemoryMapSize = 1;
+ Status = pBS->GetMemoryMap (
+ &MemoryMapSize,
+ (EFI_MEMORY_DESCRIPTOR *)TmpMemoryMap,
+ &MapKey,
+ &DescriptorSize,
+ &DescriptorVersion
+ );
+ ASSERT (Status == EFI_BUFFER_TOO_SMALL);
+ //
+ // Enlarge space here, because we will allocate pool now.
+ //
+ MemoryMapSize += EFI_PAGE_SIZE;
+ Status = pBS->AllocatePool (
+ EfiBootServicesData,
+ MemoryMapSize,
+ (VOID**)&MemoryMap
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Get System MemoryMap
+ //
+ Status = pBS->GetMemoryMap (
+ &MemoryMapSize,
+ MemoryMap,
+ &MapKey,
+ &DescriptorSize,
+ &DescriptorVersion
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ MemoryMapPtr = MemoryMap;
+ //
+ // Search the request Address
+ //
+ for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
+ switch (MemoryMap->Type){
+ case EfiMemoryMappedIO:
+ case EfiReservedMemoryType:
+ case EfiRuntimeServicesCode:
+ case EfiRuntimeServicesData:
+ case EfiUnusableMemory:
+ case EfiMemoryMappedIOPortSpace:
+ case EfiPalCode:
+ case EfiACPIReclaimMemory:
+ case EfiACPIMemoryNVS:
+ case EfiBootServicesCode:
+ case EfiBootServicesData:
+ case EfiLoaderCode:
+ case EfiLoaderData:
+ case EfiMaxMemoryType:
+ break;
+ default:
+ Size = Shl64(MemoryMap->NumberOfPages, EFI_PAGE_SHIFT);
+ MemSet((VOID*)MemoryMap->PhysicalStart, (UINTN)Size, 0);
+ }
+ MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize);
+ }
+
+ //
+ // Done
+ //
+ pBS->FreePool (MemoryMapPtr);
+
+ return IsRuntime;
+
+
+
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: ReadMORValue
+//
+// Description: Reads TCG MOR variable
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+VOID ReadMORValue( )
+{
+ CHAR16 UefiMor[] = L"MemoryOverwriteRequestControl";
+ EFI_GUID MorUefiGuid = MEMORY_ONLY_RESET_CONTROL_GUID;
+ UINT8 mor = 0;
+ UINTN size = sizeof(mor);
+ EFI_STATUS Status;
+
+
+ Status = pRS->GetVariable( UefiMor, &MorUefiGuid,
+ NULL, &size, &mor );
+
+ if(EFI_ERROR(Status))return;
+
+ if ( mor & 1 )
+ {
+
+ //clear memory
+ TRACE((-1,"MOR: before Clear memory"));
+ Status = OverwriteSystemMemory();
+ TRACE((-1,"MOR: After Clear memory"));
+ }
+}
+
+
+
+
+//**********************************************************************
+// MOR FUNCTIONS END
+//**********************************************************************
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: OnAcpiInstalled
+//
+// Description: Adds Tcg Table to Acpi Tables
+//
+// Input: IN EFI_EVENT ev
+// IN Callback Context *ctx
+//
+// Output: Device path size
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS OnAcpiInstalled(
+ IN EFI_EVENT ev,
+ IN VOID *ctx )
+{
+ EFI_STATUS Status;
+ EFI_ACPI_SUPPORT_PROTOCOL *acpi;
+ UINTN handle = 0;
+
+ TRACE((TRACE_ALWAYS, "Adding TCG ACPI table...\n"));
+ Status = pBS->LocateProtocol( &gEfiAcpiSupportGuid, NULL, &acpi );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return EFI_ABORTED;
+ }
+
+ mTcgAcpiTableTemplate.Header.Revision = TCG_TBL_REV;
+ MemCpy( mTcgAcpiTableTemplate.Header.OemId,
+ TCG_OEMID,
+ sizeof(mTcgAcpiTableTemplate.Header.OemId));
+
+ mTcgAcpiTableTemplate.Header.OemTableId = TCG_TBL_OEM_ID;
+ mTcgAcpiTableTemplate.Header.OemRevision = TCG_TBL_OEM_REV;
+ mTcgAcpiTableTemplate.Header.CreatorId = TCG_CREATOR_ID;
+ mTcgAcpiTableTemplate.Header.CreatorRevision = TCG_CREATOR_REVISION;
+ mTcgAcpiTableTemplate.Reserved = TCG_PLATFORM_CLASS;
+
+ Status = acpi->SetAcpiTable( acpi, &mTcgAcpiTableTemplate, TRUE,
+ EFI_ACPI_TABLE_VERSION_ALL,
+ &handle );
+ return Status;
+}
+
+
+
+
+
+EFI_STATUS
+EFIAPI SetTcgAcpiTable()
+{
+ EFI_STATUS Status;
+ EFI_ACPI_SUPPORT_PROTOCOL *acpi;
+ EFI_EVENT ev;
+ UINTN handle = 0;
+ static VOID *reg = NULL;
+
+ TRACE((TRACE_ALWAYS, "SetTcgAcpiTable....\n"));
+ Status = pBS->LocateProtocol( &gEfiAcpiSupportGuid, NULL, &acpi );
+
+ if(EFI_ERROR(Status)){
+
+ Status = pBS->CreateEvent( EFI_EVENT_NOTIFY_SIGNAL,
+ EFI_TPL_DRIVER,
+ OnAcpiInstalled,
+ NULL,
+ &ev );
+
+ ASSERT( !EFI_ERROR( Status ));
+ Status = pBS->RegisterProtocolNotify( &gEfiAcpiSupportGuid, ev, &reg );
+ return Status;
+ }
+
+ mTcgAcpiTableTemplate.Header.Revision = TCG_TBL_REV;
+ MemCpy( mTcgAcpiTableTemplate.Header.OemId,TCG_OEMID,
+ sizeof(mTcgAcpiTableTemplate.Header.OemId));
+
+ mTcgAcpiTableTemplate.Header.OemTableId = TCG_TBL_OEM_ID;
+ mTcgAcpiTableTemplate.Header.OemRevision = TCG_TBL_OEM_REV;
+ mTcgAcpiTableTemplate.Header.CreatorId = TCG_CREATOR_ID;
+ mTcgAcpiTableTemplate.Header.CreatorRevision = TCG_CREATOR_REVISION;
+ mTcgAcpiTableTemplate.Reserved = TCG_PLATFORM_CLASS;
+
+ Status = acpi->SetAcpiTable( acpi, &mTcgAcpiTableTemplate, TRUE,
+ EFI_ACPI_TABLE_VERSION_ALL,
+ &handle );
+
+ return Status;
+}
+
+
+static EFI_STATUS CopyLogToAcpiNVS(
+ void )
+{
+ EFI_STATUS Status;
+ TCG_LOG_HOB *TcgLog = NULL;
+ void** DummyPtr;
+
+ TcgLog = (TCG_LOG_HOB*) LocateATcgHob(
+ pST->NumberOfTableEntries,
+ pST->ConfigurationTable,
+ &gEfiAmiDTcgLogHobGuid );
+
+ DummyPtr = &TcgLog;
+
+ if ( *DummyPtr == NULL )
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ Status = pBS->AllocatePages(
+ AllocateMaxAddress,
+ EfiACPIMemoryNVS,
+ EFI_SIZE_TO_PAGES( mTcgAcpiTableTemplate.LogMaxLength + sizeof (*TcgLog)),
+ (UINT64*)(UINTN)&mTcgAcpiTableTemplate.LogStart
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ pBS->SetMem(
+ (VOID*)((UINTN)mTcgAcpiTableTemplate.LogStart),
+ (UINTN)mTcgAcpiTableTemplate.LogMaxLength,
+ 0x00 // Clean up this region with this value.
+ );
+
+ TcgLog->TableMaxSize = mTcgAcpiTableTemplate.LogMaxLength;
+
+ if(TcgDxe_Cap.deactivated){
+ TcgLog->EventNum = 0;
+ TcgLog->TableSize = 0;
+
+ pBS->CopyMem(
+ (VOID*)(UINTN)mTcgAcpiTableTemplate.LogStart,
+ TcgLog,
+ sizeof (TCG_LOG_HOB));
+
+ mTcgAcpiTableTemplate.LogStart += sizeof (*TcgLog);
+ }else{
+ pBS->CopyMem(
+ (VOID*)(UINTN)mTcgAcpiTableTemplate.LogStart,
+ TcgLog,
+ TcgLog->TableSize + sizeof (*TcgLog)
+ );
+ mTcgAcpiTableTemplate.LogStart += sizeof (*TcgLog);
+ }
+
+ Status = SetTcgAcpiTable();
+
+ return Status;
+}
+
+VOID InsertTailList(
+ EFI_LIST_ENTRY *ListHead,
+ EFI_LIST_ENTRY *Entry )
+{
+ EFI_LIST_ENTRY *_ListHead;
+ EFI_LIST_ENTRY *_BackLink;
+
+ _ListHead = ListHead;
+ _BackLink = _ListHead->BackLink;
+ Entry->ForwardLink = _ListHead;
+ Entry->BackLink = _BackLink;
+ _BackLink->ForwardLink = Entry;
+ _ListHead->BackLink = Entry;
+}
+
+typedef struct _TCG_DXE_FWVOL_LIST
+{
+ EFI_LIST_ENTRY Link;
+ EFI_HANDLE FvHandle;
+} TCG_DXE_FWVOL_LIST;
+
+static EFI_LIST_ENTRY mMeasuredFvs = {
+ &mMeasuredFvs,
+ &mMeasuredFvs
+};
+
+static EFI_STATUS AddFvToMeasuredFvList(
+ EFI_HANDLE FvHandle )
+{
+ TCG_DXE_FWVOL_LIST *NewEntry;
+
+ pBS->AllocatePool( EfiBootServicesData, sizeof (*NewEntry), &NewEntry );
+
+ if ( NewEntry == NULL )
+ {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ NewEntry->FvHandle = FvHandle;
+ InsertTailList( &mMeasuredFvs, &NewEntry->Link );
+ return EFI_SUCCESS;
+}
+
+static EFI_STATUS HashAllFilesInFv(
+ IN SHA1_CTX *Sha1Ctx,
+ IN EFI_FIRMWARE_VOLUME_PROTOCOL
+ *FwVol,
+ IN EFI_FV_FILETYPE FileType )
+{
+ EFI_STATUS Status;
+ VOID *KeyBuffer = NULL;
+ EFI_GUID FileName;
+ EFI_FV_FILE_ATTRIBUTES FileAttr;
+ UINTN FileSize;
+ VOID *FileBuffer;
+ UINT32 AuthStat;
+
+
+ Status = pBS->AllocatePool( EfiBootServicesData, FwVol->KeySize, KeyBuffer );
+
+ if ( KeyBuffer != NULL )
+ {
+ pBS->SetMem( KeyBuffer, FwVol->KeySize, 0 );
+ }
+
+ if ( KeyBuffer == NULL )
+ {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ do
+ {
+ Status = FwVol->GetNextFile(
+ FwVol,
+ KeyBuffer,
+ &FileType,
+ &FileName,
+ &FileAttr,
+ &FileSize
+ );
+
+ if ( !EFI_ERROR( Status ))
+ {
+ FileBuffer = NULL;
+ Status = FwVol->ReadFile(
+ FwVol,
+ &FileName,
+ &FileBuffer,
+ &FileSize,
+ &FileType,
+ &FileAttr,
+ &AuthStat
+ );
+ ASSERT( !EFI_ERROR( Status ));
+
+ SHA1Update(Sha1Ctx, FileBuffer, (u32)FileSize );
+ pBS->FreePool( FileBuffer );
+ }
+ } while ( !EFI_ERROR( Status ));
+
+ pBS->FreePool( KeyBuffer );
+ return EFI_SUCCESS;
+}
+
+
+
+static EFI_STATUS MeasureFv(
+ IN EFI_TCG_PROTOCOL *This,
+ IN EFI_HANDLE FvHandle )
+{
+ EFI_STATUS Status;
+ EFI_FIRMWARE_VOLUME_PROTOCOL *FwVol;
+ EFI_LIST_ENTRY *Link;
+ TCG_DXE_FWVOL_LIST *FwVolList;
+ SHA1_CTX Sha1Ctx;
+ TCG_DIGEST *FvDigest;
+ EFI_TCG_PCR_EVENT TcgEvent;
+ UINT32 EventNum;
+
+ for ( Link = mMeasuredFvs.ForwardLink;
+ Link != &mMeasuredFvs;
+ Link = Link->ForwardLink )
+ {
+ FwVolList = _CR( Link, TCG_DXE_FWVOL_LIST, Link );
+
+ if ( FvHandle == FwVolList->FvHandle )
+ {
+ return EFI_SUCCESS;
+ }
+ }
+
+ Status = AddFvToMeasuredFvList( FvHandle );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ Status = pBS->HandleProtocol(
+ FvHandle,
+ &gEfiFirmwareVolumeProtocolGuid,
+ &FwVol
+ );
+ ASSERT( !EFI_ERROR( Status ));
+
+ SHA1Init(&Sha1Ctx );
+ Status = HashAllFilesInFv( &Sha1Ctx, FwVol, EFI_FV_FILETYPE_DRIVER );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+ Status = HashAllFilesInFv( &Sha1Ctx, FwVol, EFI_FV_FILETYPE_APPLICATION );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+ SHA1Final((unsigned char *)&FvDigest->digest, &Sha1Ctx);
+
+ TcgEvent.Header.PCRIndex = PCRi_OPROM_CODE;
+ TcgEvent.Header.EventType = EV_EVENT_TAG;
+ TcgEvent.Event.Tagged.EventID = EV_ID_OPROM_EXECUTE;
+ TcgEvent.Event.Tagged.EventSize
+ = sizeof (TcgEvent.Event.Tagged.EventData.OptionRomExecute);
+ TcgEvent.Header.EventDataSize
+ = _TPM_STRUCT_PARTIAL_SIZE( struct _EFI_TCG_EV_TAG, EventData )
+ + TcgEvent.Event.Tagged.EventSize;
+
+ TcgEvent.Event.Tagged.EventData.OptionRomExecute.PFA = 0;
+ TcgEvent.Event.Tagged.EventData.OptionRomExecute.Reserved = 0;
+ TcgEvent.Event.Tagged.EventData.OptionRomExecute.Hash = *FvDigest;
+
+ Status = TcgDxeHashLogExtendEvent(
+ This,
+ (UINTN)&TcgEvent.Event,
+ TcgEvent.Header.EventDataSize,
+ TCG_ALG_SHA,
+ (TCG_PCR_EVENT*)&TcgEvent,
+ &EventNum,
+ 0
+ );
+
+Exit:
+ return Status;
+}
+
+
+
+
+static
+VOID
+EFIAPI OnFwVolInstalled(
+ IN EFI_EVENT Event,
+ IN VOID *Context )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE *Handles;
+ UINTN NumHandles;
+
+ Handles = NULL;
+ NumHandles = 0;
+ Status = pBS->LocateHandleBuffer(
+ ByRegisterNotify,
+ NULL,
+ *(VOID**)Context,
+ &NumHandles,
+ &Handles
+ );
+
+ ASSERT(!EFI_ERROR( Status ));
+
+ while (!EFI_ERROR( Status ) && NumHandles > 0 )
+ {
+ NumHandles--;
+ Status = MeasureFv( &mTcgDxeData.TcgServiceProtocol,
+ Handles[NumHandles] );
+ }
+
+ if ( Handles != NULL )
+ {
+ pBS->FreePool( Handles );
+ }
+}
+
+static EFI_STATUS MonitorFvs(
+ void )
+{
+ EFI_STATUS Status;
+ EFI_EVENT Event;
+ static VOID *RegFwVol;
+
+ Status = pBS->CreateEvent(
+ EFI_EVENT_NOTIFY_SIGNAL,
+ EFI_TPL_DRIVER,
+ OnFwVolInstalled,
+ (VOID*)&RegFwVol,
+ &Event
+ );
+ ASSERT( !EFI_ERROR( Status ));
+
+ Status = pBS->RegisterProtocolNotify(
+ &gEfiFirmwareVolumeProtocolGuid,
+ Event,
+ &RegFwVol
+ );
+ ASSERT( !EFI_ERROR( Status ));
+
+ return Status;
+}
+
+
+#define FAST_BOOT_VARIABLE_GUID \
+ { 0xb540a530, 0x6978, 0x4da7, 0x91, 0xcb, 0x72, 0x7, 0xd7, 0x64, 0xd2, 0x62 }
+EFI_GUID FastBootVariableGuid = FAST_BOOT_VARIABLE_GUID;
+EFI_GUID AmitcgefiOsVariableGuid = AMI_TCG_EFI_OS_VARIABLE_GUID;
+
+
+
+
+
+
+//*******************************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: FindAndMeasureDxeFWVol
+//
+// Description:
+//
+// Input:
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//******************************************************************************
+EFI_STATUS FindAndMeasureDxeFWVol()
+{
+ PEI_EFI_POST_CODE ev;
+ UINT32 n;
+ UINTN last;
+ EFI_STATUS Status;
+ EFI_GUID NameGuid =\
+ {0x7739f24c, 0x93d7, 0x11d4,\
+ 0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d};
+ UINTN Size;
+ void *Buffer = NULL;
+ EFI_TCG_PROTOCOL *TcgProtocol;
+ VOID *HobStart;
+ UINTN TableEntries;
+ EFI_PEI_HOB_POINTERS FirmwareVolumeHob;
+ BOOLEAN Found=FALSE;
+
+ TableEntries = pST->NumberOfTableEntries;
+
+ while ( TableEntries > 0 )
+ {
+ TableEntries--;
+
+ if ((!MemCmp(
+ &pST->ConfigurationTable[TableEntries].VendorGuid,
+ &NameGuid, sizeof(EFI_GUID))))
+ {
+ HobStart = pST->ConfigurationTable[TableEntries].VendorTable;
+ FirmwareVolumeHob.Raw = GetHob (EFI_HOB_TYPE_FV, HobStart);
+ if (FirmwareVolumeHob.Header->HobType != EFI_HOB_TYPE_FV) {
+ continue;
+ }
+ break;
+ }
+ }
+
+ for (Status = EFI_NOT_FOUND; EFI_ERROR (Status);) {
+ if (END_OF_HOB_LIST (FirmwareVolumeHob)) {
+ return EFI_NOT_FOUND;
+ }
+
+ if (GET_HOB_TYPE (FirmwareVolumeHob) == EFI_HOB_TYPE_FV) {
+ if ((((UINT64)FirmwareVolumeHob.FirmwareVolume->BaseAddress)\
+ < (UINT64)NVRAM_ADDRESS ) ||
+ ((UINT64)FirmwareVolumeHob.FirmwareVolume->BaseAddress) == FV_MAIN_BASE)
+ {
+ Found = TRUE;
+ break;
+ }
+ }
+
+ FirmwareVolumeHob.Raw = GET_NEXT_HOB (FirmwareVolumeHob);
+ }
+
+ if(Found== FALSE)return EFI_NOT_FOUND;
+
+ TRACE((-1,"TcgDxe:: Found Volume: Base = %x Length = %x",\
+ FirmwareVolumeHob.FirmwareVolume->BaseAddress,\
+ FirmwareVolumeHob.FirmwareVolume->Length));
+
+ Status = pBS->AllocatePool(
+ EfiBootServicesData,
+ (UINTN)FirmwareVolumeHob.FirmwareVolume->Length,
+ &Buffer);
+
+ if(EFI_ERROR(Status) || Buffer == NULL) return EFI_OUT_OF_RESOURCES;
+
+ Status = pBS->LocateProtocol (&gEfiTcgProtocolGuid,\
+ NULL, &TcgProtocol);
+ if(EFI_ERROR(Status)){
+ return Status;
+ }
+
+ if(FirmwareVolumeHob.FirmwareVolume->BaseAddress == FV_MAIN_BASE)
+ {
+ if(FirmwareVolumeHob.FirmwareVolume->Length > TCG_SIZE){
+ Size = TCG_SIZE;
+ }else{
+ Size = (UINTN)FirmwareVolumeHob.FirmwareVolume->Length;
+ }
+
+ pBS->CopyMem(Buffer, (UINT8 *)(EFI_PHYSICAL_ADDRESS)FirmwareVolumeHob.FirmwareVolume->BaseAddress,\
+ Size);
+
+ }else{
+
+ Buffer = (UINT8 *)(EFI_PHYSICAL_ADDRESS)FirmwareVolumeHob.FirmwareVolume->BaseAddress;
+ Size = (UINTN)FirmwareVolumeHob.FirmwareVolume->Length;
+ }
+
+ ev.Header.PCRIndex = PCRi_CRTM_AND_POST_BIOS;
+ ev.Header.EventType = EV_POST_CODE;
+ ev.Header.EventDataSize = sizeof (EFI_TCG_EV_POST_CODE);
+ ev.Event.PostCodeAddress = \
+ (EFI_PHYSICAL_ADDRESS)FirmwareVolumeHob.FirmwareVolume->BaseAddress;
+
+ #if defined x64_BUILD && x64_BUILD == 1
+ ev.Event.PostCodeLength = Size;
+ #else
+ ev.Event.PostCodeLength = Size;
+ #endif
+
+ Status = TcgProtocol->HashLogExtendEvent (TcgProtocol,
+ (EFI_PHYSICAL_ADDRESS)Buffer,
+ Size,
+ TCG_ALG_SHA,
+ (TCG_PCR_EVENT*)&ev,
+ #if defined x64_BUILD && x64_BUILD == 1
+ &n,
+ &last);
+ #else
+ &n,
+ (EFI_PHYSICAL_ADDRESS *)&last);
+ #endif
+
+ return Status;
+}
+
+
+
+EFI_STATUS
+EFIAPI TcgDxeEntry(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ BOOLEAN Support = FALSE;
+ TPM_GetCapabilities_Input cmdGetCap;
+ TPM_RQU_COMMAND_HDR NuvotoncmdGetTpmStatus;
+ UINT8 result[0x100];
+
+ Status = pBS->LocateProtocol(
+ &gEfiTpmDeviceProtocolGuid,
+ NULL,
+ &mTcgDxeData.TpmDevice);
+
+ Status = pBS->LocateProtocol(
+ &gEfiTpmDeviceProtocolGuid,
+ NULL,
+ &mTcmDxeData.TpmDevice);
+
+ if ( EFI_ERROR( Status )){
+ return Status;
+ }
+
+ Status = CopyLogToAcpiNVS( );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ if(*(UINT16 *)(UINTN)(PORT_TPM_IOMEMBASE + 0xF00) != 0x1050)
+ {
+ cmdGetCap.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdGetCap.ParamSize = TPM_H2NL( sizeof (cmdGetCap));
+
+ if(AutoSupportType()){
+ cmdGetCap.CommandCode = TPM_H2NL( TCM_ORD_GetCapability );
+ cmdGetCap.CommandCode = TPM_H2NL( TCM_ORD_GetCapability );
+ cmdGetCap.caparea = TPM_H2NL( TPM_CAP_FLAG );
+ }else{
+ cmdGetCap.CommandCode = TPM_H2NL( TPM_ORD_GetCapability );
+ cmdGetCap.CommandCode = TPM_H2NL( TPM_ORD_GetCapability );
+ cmdGetCap.caparea = TPM_H2NL( TPM_CAP_FLAG );
+ }
+
+ cmdGetCap.subCapSize = TPM_H2NL( 4 ); // subCap is always 32bit long
+ cmdGetCap.subCap = TPM_H2NL( TPM_CAP_FLAG_PERMANENT );
+
+ if(AutoSupportType()){
+ Status = TcgDxePassThroughToTcm( &mTcmDxeData.TcgServiceProtocol,
+ sizeof (cmdGetCap),
+ (UINT8*)&cmdGetCap,
+ sizeof (TPM_Capabilities_PermanentFlag),
+ (UINT8*)&TcgDxe_Cap );
+ }else{
+ Status = TcgDxePassThroughToTpm( &mTcgDxeData.TcgServiceProtocol,
+ sizeof (cmdGetCap),
+ (UINT8*)&cmdGetCap,
+ sizeof (TPM_Capabilities_PermanentFlag),
+ (UINT8*)&TcgDxe_Cap );
+ }
+ }else{
+ MemSet(&TcgDxe_Cap,sizeof(TPM_Capabilities_PermanentFlag), 0);
+ NuvotoncmdGetTpmStatus.tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ NuvotoncmdGetTpmStatus.paramSize = TPM_H2NL( sizeof (TPM_RQU_COMMAND_HDR));
+ NuvotoncmdGetTpmStatus.ordinal = TPM_H2NL( NTC_ORD_GET_TPM_STATUS );
+
+ Status = TcgDxePassThroughToTpm( &mTcgDxeData.TcgServiceProtocol,
+ sizeof (NuvotoncmdGetTpmStatus),
+ (UINT8*)&NuvotoncmdGetTpmStatus,
+ 0x100,
+ result );
+
+ if(((NUVOTON_SPECIFIC_FLAGS *) result)->RetCode == 0)
+ {
+ if(((NUVOTON_SPECIFIC_FLAGS *)result)->isdisabled){
+ TcgDxe_Cap.disabled = 1;
+ }
+
+ if(((NUVOTON_SPECIFIC_FLAGS *)result)->isdeactivated){
+ TcgDxe_Cap.deactivated = 1;
+ }
+
+ if(((NUVOTON_SPECIFIC_FLAGS *)result)->isOwnerSet){
+ TcgDxe_Cap.ownership = 1;
+ }
+ }else{
+
+ TcgDxe_Cap.RetCode = ((NUVOTON_SPECIFIC_FLAGS *)result)->RetCode;
+ }
+ }
+
+ if ( TPM_H2NL(TcgDxe_Cap.RetCode)!=0)
+ {
+ return EFI_SUCCESS;
+ }
+
+ Support = AutoSupportType();
+
+ ReadMORValue();
+
+ if(!Support){
+ Status = pBS->InstallMultipleProtocolInterfaces(
+ &ImageHandle,
+ &gEfiTcgProtocolGuid,
+ &mTcgDxeData.TcgServiceProtocol,
+ NULL);
+#if defined (USE_BIOS_IMAGE_AS_CRTM) && (USE_BIOS_IMAGE_AS_CRTM == 0)
+ FindAndMeasureDxeFWVol();
+#endif
+ return Status;
+ }else{
+
+ TcmOSTransition();
+ return pBS->InstallMultipleProtocolInterfaces(
+ &ImageHandle,
+ &gEfiTcgProtocolGuid,
+ &mTcmDxeData.TcgServiceProtocol,
+ NULL);
+ }
+
+}
diff --git a/Core/EM/TCG2/Common/TcgDxe.cif b/Core/EM/TCG2/Common/TcgDxe.cif
new file mode 100644
index 0000000..20e2b7f
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgDxe.cif
@@ -0,0 +1,17 @@
+<component>
+ name = "TcgDxe"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common"
+ RefName = "TcgDxe"
+[files]
+"TcgDxe.mak"
+"TpmDxe.c"
+"TcgDxe.c"
+"TcgDxe.dxs"
+"xTcgDxe.c"
+"EMpCallBin.asm"
+"EMpCallBin32.asm"
+"EMpTcmDxe.c"
+"TcgDxe20.c"
+"TcgDxe.sdl"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/TcgDxe.dxs b/Core/EM/TCG2/Common/TcgDxe.dxs
new file mode 100644
index 0000000..05479e0
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgDxe.dxs
@@ -0,0 +1,110 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TcgDxe.dxs 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TcgDxe.dxs $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:03p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 7 3/19/12 6:31p Fredericko
+// Changes for Tcg Performance Metrics Improvement.
+// Files Changed: Tcg.sdl, TcgMisc.h, TcgDxe.c, TcgCommon.c, TcgCommon.h,
+// AmiTcgPlatformPeiLib.c, AmiTcgPlatformDxe.c, TcgDxe.dxs
+//
+// 6 5/20/10 8:59a Fredericko
+// Included File Header
+// Updated AMI copyright header
+//
+// 5 4/30/09 6:17p Fredericko
+// Updated Header Date
+//
+// 4 4/30/09 5:34p Fredericko
+// AMI company Header Address changes
+//
+// 3 2/05/09 5:25p Fredericko
+// To build without EDK changed includes in Tcgdxe.dxs file
+//
+// 2 3/06/07 12:59p Fasihm
+// Added dependencies.
+//
+// 1 6/20/06 5:58p Andriyn
+//
+//**********************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgDxe.dxs
+//
+// Description:
+// TcgDxe dependency file
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+//<AMI_FHDR_START>
+//---------------------------------------------------------------------------
+// Name: TCGDXE.dxs
+//
+// Description: Dependency expression for TCGPEI component.
+//
+//---------------------------------------------------------------------------
+//<AMI_FHDR_END>
+#include <Token.h>
+#include <Protocol\Variable.h>
+#include <Protocol\CpuIo.h>
+#if (PI_SPECIFICATION_VERSION < 0x00010000)
+#include <Protocol\FirmwareVolume.h>
+#else
+#include <Protocol\FirmwareVolume2.h>
+#endif
+
+
+DEPENDENCY_START
+ EFI_VARIABLE_ARCH_PROTOCOL_GUID AND
+ EFI_CPU_IO_PROTOCOL_GUID AND
+#if (PI_SPECIFICATION_VERSION < 0x00010000)
+ EFI_FIRMWARE_VOLUME_PROTOCOL_GUID
+#else
+ EFI_FIRMWARE_VOLUME2_PROTOCOL_GUID
+#endif
+DEPENDENCY_END
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/TcgDxe.mak b/Core/EM/TCG2/Common/TcgDxe.mak
new file mode 100644
index 0000000..5a13732
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgDxe.mak
@@ -0,0 +1,196 @@
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
+#**********************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TcgDxe.mak 1 4/21/14 2:16p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:16p $
+#**********************************************************************
+#**********************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TcgDxe.mak $
+#
+# 1 4/21/14 2:16p Fredericko
+#
+# 1 10/08/13 12:03p Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 2 10/03/13 1:59p Fredericko
+#
+# 1 7/10/13 5:51p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+#
+# 29 9/27/11 10:25p Fredericko
+# [TAG] EIP67286
+# [Category] Improvement
+# [Description] changes for Tcg Setup policy
+# [Files] Tcg.sdl
+# TcgPei.cif
+# TcgPei.mak
+# xtcgPei.c
+# xTcgPeiAfterMem.c
+# TcgPeiAfterMem.mak
+# TcgDxe.cif
+# TcgDxe.mak
+# xTcgDxe.c
+# AmiTcgPlatformPeilib.c
+# AmiTcgPlatformDxelib.c
+#
+# 28 3/29/11 1:12p Fredericko
+#
+# 27 3/28/11 2:17p Fredericko
+# [TAG] EIP 54642
+# [Category] Improvement
+# [Description] 1. Checkin Files related to TCG function override
+# 2. Include TCM and TPM auto detection
+# [Files] Affects all TCG files
+#
+# 26 6/30/10 3:05p Fredericko
+# Modified for building EMpCallBin32.asm
+#
+# 25 5/19/10 5:26p Fredericko
+# Updated AMI copy right header
+# EIP 37653
+#
+# 24 4/21/10 11:49a Fredericko
+# Changes on the way Post strings are created for PPI display for
+# multi-language support
+#
+# 23 4/20/10 12:35p Fredericko
+# Included dependency on SetupStrTokens.h.
+#
+# 22 3/23/10 6:53p Fredericko
+# Tcglegacy support is currently it's own subcomponent
+#
+# 21 3/19/10 4:15p Fredericko
+# modified for legacy IO interface support
+#
+# 20 6/01/09 4:08p Fredericko
+# Changes for building Tcgdxe ffs when TCM_SUPPORT is enabled or
+# Disabled.
+#
+# 19 4/30/09 6:15p Fredericko
+# Updated Header Date
+#
+# 18 4/30/09 5:31p Fredericko
+# Removed unneccesary directories paths and AMI company Header Address
+# changes
+#
+# 17 2/05/09 5:10p Fredericko
+# USE BUILD_DEFAULTS instead of EDK_DEFAULTS and removal of all EDK paths
+#
+# 16 4/10/08 5:29p Fredericko
+# Print Library added
+#
+# 15 11/02/07 4:26p Fredericko
+# Changes to support Montevina Build process
+#
+# 1 10/26/07 9:41a Fasihm
+# Changed the Link order of the Libraries.
+# Need to remove after TCG is labeled again.
+#
+# 14 9/26/07 4:52p Fredericko
+#
+# 13 9/04/07 6:10p Fredericko
+# Cflags defined to make compiler use \W4 switch instead of \W3 switch
+#
+# 12 9/04/07 10:16a Fredericko
+# Use of AMIDXELIB.
+#
+# 11 7/13/07 2:53p Rameshraju
+# Added the TPM post meesage based on the UNI string.
+#
+#**********************************************************************
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: TcgDxe.MAK
+#
+# Description: Make file for the tcgdxe component
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+all : TCGDXE
+
+TCGDXE : $(BUILD_DIR)\tcgdxe.mak tcgdxeBin #$(BUILD_DIR)\LEGX16.ffs $(BUILD_DIR)\MPTPM.ffs $(BUILD_DIR)\TPM32BIN.ffs
+!IF "$(AMI_ZTEIC_SUPPORT)" == "1"
+TCGDXE : $(BUILD_DIR)\tcgdxe.mak tcgdxeBin
+!ENDIF
+
+$(BUILD_DIR)\tcgdxe.mak : $(TCGDXE_DIR)\$(@B).cif $(TCGDXE_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(TCGDXE_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+TCGDXE_CFLAGS=$(CFLAGS) \
+ /I$(TCG_DIR)\
+ /I$(TPM12_DIR)\
+ /I$(TPM20_CRBLIB)\
+ /I$(TCG_DIR)\Common\
+ /I$(PROJECT_DIR)\Include\Protocol\
+ /I$(TCG_DIR)\Protocol\
+ /I$(TcgPlatformSetupPolicy_DIR)\
+
+
+!IF "$(x64_BUILD)" != "0"
+$(BUILD_DIR)\$(TCGDXE_DIR)\EMpCallBin.obj : $(TCGDXE_DIR)\EMpCallBin.asm
+ $(ASM) /c /nologo /Fo$$(BUILD_DIR)\$(TCG_DIR)\EMpCallBin.obj $(TCG_DIR)\EMpCallBin.asm
+!ELSE
+$(BUILD_DIR)\$(TCGDXE_DIR)\EMpCallBin32.obj : $(TCGDXE_DIR)\EMpCallBin32.asm
+ $(ASM) /c /nologo /Fo$$(BUILD_DIR)\$(TCGDXE_DIR)\EMpCallBin32.obj $(TCGDXE_DIR)\EMpCallBin32.asm
+!ENDIF
+
+
+TCGDXE_OBJECTS = \
+$(BUILD_DIR)\$(TCGDXE_DIR)\TpmDxe.obj \
+$(BUILD_DIR)\$(TCGDXE_DIR)\TcgDxe.obj \
+$(BUILD_DIR)\$(TCGDXE_DIR)\TcgDxe20.obj \
+$(BUILD_DIR)\$(TCGDXE_DIR)\xTcgDxe.obj \
+$(BUILD_DIR)\$(TCGDXE_DIR)\EMpTcmDxe.obj\
+!IF "$(x64_BUILD)" == "0"
+$(BUILD_DIR)\$(TCGDXE_DIR)\EMpCallBin32.obj\
+!ENDIF
+!IF "$(x64_BUILD)" == "1"
+$(BUILD_DIR)\$(TCGDXE_DIR)\EMpCallBin.obj\
+!ENDIF
+
+
+tcgdxeBin : $(AMIDXELIB) $(BUILD_DIR)\TisLib.lib $(BUILD_DIR)\Tpm20CRBLib.lib
+ @echo CFLAGS=$(CFLAGS)
+ @echo TCGDXE_CFLAGS=$(TCGDXE_CFLAGS)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\tcgdxe.mak all\
+ "CFLAGS=$(TCGDXE_CFLAGS)"\
+ GUID=5E9CABA3-F2B1-497a-ADAC-24F575E9CDE9 \
+ ENTRY_POINT=CommonTcgDxEntryPoint \
+ TYPE=BS_DRIVER \
+ "OBJECTS=$(TCGDXE_OBJECTS)"\
+ DEPEX1=$(TCGDXE_DIR)\tcgdxe.dxs \
+ DEPEX1_TYPE=EFI_SECTION_DXE_DEPEX \
+ COMPRESS=1 HAS_RESOURCES=1\
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
diff --git a/Core/EM/TCG2/Common/TcgDxe.sdl b/Core/EM/TCG2/Common/TcgDxe.sdl
new file mode 100644
index 0000000..c57b3a2
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgDxe.sdl
@@ -0,0 +1,27 @@
+TOKEN
+ Name = "TcgDxeSupport"
+ Value = "1"
+ Help = "Enable or Diasble TcgPeiSupport"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetH = Yes
+ TargetMAK = Yes
+ Master = Yes
+ Token = "TCG2Support" "=" "1"
+End
+
+PATH
+ Name = "TCGDXE_DIR"
+End
+
+MODULE
+ Help = "Includes tcgdxe.mak into project"
+ Path = "$(TCGDXE_DIR)"
+ File = "tcgdxe.mak"
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\tcgdxe.ffs"
+ Parent = "$(BUILD_DIR)\TcgPlatformSetupPolicy.ffs"
+ InvokeOrder = AfterParent
+End
diff --git a/Core/EM/TCG2/Common/TcgDxe20.c b/Core/EM/TCG2/Common/TcgDxe20.c
new file mode 100644
index 0000000..981a88a
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgDxe20.c
@@ -0,0 +1,853 @@
+/*++
+ Module Name:
+
+ TcgDxe.c
+
+ Abstract:
+
+ DXE Driver that provides TCG services
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TcgDxe20.c 3 6/14/14 12:29a Fredericko $
+//
+// $Revision: 3 $
+//
+// $Date: 6/14/14 12:29a $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log:
+#include "TcgCommon.h"
+#include <TcgMisc.h>
+#include <Token.h>
+#include <AmiDxeLib.h>
+#include <Runtime.h>
+#include <Tpm20Includes\Tpm20.h>
+#include <Tpm20Includes\TrEEProtocol.h>
+#include "protocol\TpmDevice\TpmDevice.h"
+#include <Protocol\ComponentName.h>
+#include <Protocol\ComponentName2.h>
+#include <Protocol\DriverBinding.h>
+#include <Protocol\AcpiSupport.h>
+#include "TcgPlatformSetupPolicy.h"
+#include <Acpi.h>
+#include <AcpiRes.h>
+#include "Tpm20CRBLib.h"
+
+/*
+ locates the TPM20 hob from Pei. If found we are processing TPM 20 devic
+ need to install the TreeProtocol and do TPM20 binding measurements
+*/
+#define MAX_LOG_AREA_SIZE (32 * 1024) // 32KB
+
+static EFI_PHYSICAL_ADDRESS TreeEventLogLocation;
+static EFI_PHYSICAL_ADDRESS LastEntry = NULL;
+static EFI_PHYSICAL_ADDRESS LastEventPtr = 0;
+static EFI_TPM_DEVICE_PROTOCOL *TpmDevice=NULL;
+
+BOOLEAN IsTpm20Device();
+
+typedef struct _AMI_INTERNAL_HLXE_PROTOCOL AMI_INTERNAL_HLXE_PROTOCOL;
+
+typedef
+EFI_STATUS
+(EFIAPI * INTERNAL_HASH_LOG_EXTEND_EVENT) (
+ IN UINT8 *DataToHash,
+ IN UINT64 Flags,
+ IN UINTN DataSize,
+ IN OUT TCG_PCR_EVENT_HDR *NewEventHdr,
+ IN UINT8 *NewEventData
+);
+
+
+struct _AMI_INTERNAL_HLXE_PROTOCOL {
+ INTERNAL_HASH_LOG_EXTEND_EVENT InternalHashLogExtend;
+};
+
+
+static UINT16 *gDriverName=L"TPM Driver";
+static BOOLEAN Tpm20FwDevice = FALSE;
+
+
+UINT8 GetHashPolicy()
+{
+ TCG_PLATFORM_SETUP_PROTOCOL *ProtocolInstance;
+ EFI_STATUS Status;
+ EFI_GUID Policyguid = TCG_PLATFORM_SETUP_POLICY_GUID;
+
+ Status = pBS->LocateProtocol (&Policyguid, NULL, &ProtocolInstance);
+ if (EFI_ERROR (Status)) {
+ return 0;
+ }
+
+ return(ProtocolInstance->ConfigFlags.Reserved1);
+}
+
+
+EFI_STATUS
+EFIAPI
+Tpm20ComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+{
+ //Supports only English
+ if(!Language || !DriverName) return EFI_INVALID_PARAMETER;
+
+ if (!LanguageCodesEqual( Language, "en-US") &&
+ !LanguageCodesEqual( Language, "eng"))
+ return EFI_UNSUPPORTED;
+ else
+ *DriverName=gDriverName;
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+Tpm20ComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+Tpm20ComponentNameGetDriverName2 (
+ IN EFI_COMPONENT_NAME2_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+{
+ //Supports only English
+ if(!Language || !DriverName) return EFI_INVALID_PARAMETER;
+//LANGUAGE_CODE_ENGLISH
+ if (!LanguageCodesEqual( Language, "en-US") &&
+ !LanguageCodesEqual( Language, "eng"))
+ return EFI_UNSUPPORTED;
+ else
+ *DriverName=gDriverName;
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+Tpm20ComponentNameGetControllerName2 (
+ IN EFI_COMPONENT_NAME2_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+static EFI_COMPONENT_NAME_PROTOCOL gComponentName = {
+ Tpm20ComponentNameGetDriverName,
+ Tpm20ComponentNameGetControllerName,
+ LANGUAGE_CODE_ENGLISH
+};
+
+
+static EFI_COMPONENT_NAME2_PROTOCOL gComponentName2 = {
+ Tpm20ComponentNameGetDriverName2,
+ Tpm20ComponentNameGetControllerName2,
+ LANGUAGE_CODE_ENGLISH
+};
+
+
+EFI_STATUS
+EFIAPI
+Tpm20DriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Controller,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
+ )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ static BOOLEAN Initialized = FALSE;
+
+ if(Initialized == FALSE){
+ Initialized = TRUE;
+ if(IsTpm20Device()){
+ return EFI_SUCCESS;
+ }else if(Tpm20FwDevice)return EFI_SUCCESS;
+ }
+
+ return EFI_UNSUPPORTED;
+}
+
+
+EFI_STATUS
+EFIAPI
+Tpm20DriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Controller,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
+ )
+{
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+Tpm20DriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Controller,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_DRIVER_BINDING_PROTOCOL Tpm20DriverBinding = {
+ Tpm20DriverBindingSupported,
+ Tpm20DriverBindingStart,
+ Tpm20DriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+
+
+EFI_STATUS
+__stdcall Tcg20CommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PcrIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue );
+
+
+
+BOOLEAN IsTpm20Device()
+{
+ EFI_GUID gTpm20Supporthobguid = TPM20_HOB_GUID;
+ UINT8 *TpmSupport = NULL;
+
+ TpmSupport = LocateATcgHob( pST->NumberOfTableEntries,
+ pST->ConfigurationTable,
+ &gTpm20Supporthobguid);
+
+ if(TpmSupport != NULL){
+ if((*(volatile UINT8 *)((UINTN)(0xfed40000))!=0xff)){
+ if(*TpmSupport == 1)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
+EFI_STATUS
+TreeGetCapability (
+ IN EFI_TREE_PROTOCOL *This,
+ IN OUT TREE_BOOT_SERVICE_CAPABILITY *ProtocolCapability
+ )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ UINT8 HashAlg = GetHashPolicy();
+
+ if((ProtocolCapability == NULL) || (This == NULL)){
+ Status = EFI_INVALID_PARAMETER;
+ }
+ else {
+ if(ProtocolCapability->Size < (sizeof(UINT8) + sizeof(TREE_VERSION) + sizeof(TREE_VERSION))){
+ Status = EFI_BUFFER_TOO_SMALL;
+ }
+ else {
+ ProtocolCapability->StructureVersion.Major = 1;
+ ProtocolCapability->StructureVersion.Minor = 0;
+ ProtocolCapability->ProtocolVersion.Major = 1;
+ ProtocolCapability->ProtocolVersion.Minor = 0;
+
+ if (ProtocolCapability->Size < sizeof(TREE_BOOT_SERVICE_CAPABILITY)){
+ ProtocolCapability->Size = sizeof(TREE_BOOT_SERVICE_CAPABILITY);
+ Status = EFI_BUFFER_TOO_SMALL;
+ }
+ else {
+
+ if( HashAlg == 0){
+ ProtocolCapability->HashAlgorithmBitmap = TREE_BOOT_HASH_ALG_SHA1;
+ }else if(HashAlg == 1){
+ ProtocolCapability->HashAlgorithmBitmap = TREE_BOOT_HASH_ALG_SHA256;
+ }
+
+ ProtocolCapability->SupportedEventLogs = TREE_EVENT_LOG_FORMAT_TCG_1_2;
+ ProtocolCapability->TrEEPresentFlag = TRUE;
+ ProtocolCapability->MaxCommandSize = 0x0F80;
+ ProtocolCapability->MaxResponseSize = 0x0F80;
+ ProtocolCapability->ManufacturerID = *(UINT16 *)(UINTN)(PORT_TPM_IOMEMBASE + 0xF00);
+ }
+ }
+ }
+
+ return Status;
+}
+
+
+EFI_STATUS
+TreeGetEventLog (
+ IN EFI_TREE_PROTOCOL *This,
+ IN TREE_EVENTLOGTYPE EventLogFormat,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLocation,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry,
+ OUT BOOLEAN *EventLogTruncated
+ )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+
+ if(EventLogFormat != TREE_EVENT_LOG_FORMAT_TCG_1_2)
+ {
+ Status = EFI_INVALID_PARAMETER;
+ }
+
+ *EventLogLocation = TreeEventLogLocation;
+ *EventLogLastEntry = LastEventPtr;
+ *EventLogTruncated = FALSE;
+
+ return Status;
+}
+
+
+EFI_STATUS
+InternalTcg20CommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PcrIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue )
+{
+ TPM2_PCRExtend_cmd_t Cmd;
+ TPM2_PCRExtend_res_t Res;
+ TPM2_PCRExtend_res_t Tmpres;
+ UINT32 CmdSize;
+ UINT8 *Buffer;
+ UINT8 *AuthSizeOffset;
+ UINT8 *ResultBuf = NULL;
+ UINT32 ResultBufSize = 0;
+ UINT32 DigestSize;
+ EFI_STATUS Status;
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+
+ Cmd.Tag = (TPMI_ST_COMMAND_TAG)TPM_H2NS(TPM_ST_SESSIONS);
+ Cmd.CommandSize = TPM_H2NL(sizeof(Cmd));
+ Cmd.CommandCode = TPM_H2NL(TPM_CC_PCR_Extend);
+
+ Buffer = (UINT8 *)&Cmd.inputParameters;
+ *(UINT32 *)Buffer = TPM_H2NL(PcrIndex);
+ Buffer += sizeof(UINT32);
+
+ AuthSizeOffset = Buffer;
+ *(UINT32 *)Buffer = 0;
+ Buffer += sizeof(UINT32);
+
+ // pcr authHandle
+ *(UINT32 *)Buffer = TPM_H2NL(TPM_RS_PW);
+ Buffer += sizeof(UINT32);
+
+ // nonce = nullNonce
+ *(UINT16 *)Buffer = 0;
+ Buffer += sizeof(UINT16);
+
+ // sessionAttributes = 0
+ *(UINT8 *)Buffer = 0;
+ Buffer += sizeof(UINT8);
+
+ // auth = nullAuth
+ *(UINT16 *)Buffer = 0;
+ Buffer += sizeof(UINT16);
+
+ // authorizationSize
+ *(UINT32 *)AuthSizeOffset = TPM_H2NL((UINT32)(Buffer - AuthSizeOffset - sizeof(UINT32)));
+
+ //Digest count
+ *(UINT32 *)Buffer = TPM_H2NL(1);
+ Buffer += sizeof(UINT32);
+
+
+ // Get the digest size based on Hash Alg
+ if(GetHashPolicy()==0){
+ //Hash alg
+ *(UINT16 *)Buffer = TPM_H2NS(TPM2_ALG_SHA1);
+ Buffer += sizeof(UINT16);
+ DigestSize = 0x14;
+ TcgCommonCopyMem(CallbackContext, Buffer, &Digest->digest, DigestSize);
+ }else{
+ //Hash alg
+ /**(UINT16 *)Buffer = TPM_H2NS(TPM2_ALG_SHA256);
+ Buffer += sizeof(UINT16);
+ DigestSize = 0x20;
+ TcgCommonCopyMem(CallbackContext, Buffer, &Digest->digestSha2, DigestSize);*/
+ return EFI_UNSUPPORTED;
+ }
+
+ Buffer += DigestSize;
+
+ CmdSize = (UINT32)(Buffer - (UINT8 *)&Cmd);
+ Cmd.CommandSize = TPM_H2NL(CmdSize);
+
+ ResultBuf = (UINT8 *) &Tmpres;
+ ResultBufSize = sizeof(Res);
+
+ if(Tpm20FwDevice ==FALSE)
+ {
+ TRACE(( TRACE_ALWAYS," Tpm20FwDevice = FALSE \n"));
+ if(TpmDevice==NULL)return EFI_NOT_FOUND;
+
+ InBuffer[0].Buffer = &Cmd;
+ InBuffer[0].Size = CmdSize;
+ OutBuffer[0].Buffer = ResultBuf;
+ OutBuffer[0].Size = ResultBufSize;
+
+ TpmDevice->Init(TpmDevice );
+
+ Status = TpmDevice->Transmit(TpmDevice,
+ sizeof (InBuffer) / sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer);
+
+ TpmDevice->Close(TpmDevice );
+ }else{
+ Status = CrbSubmitCmd((UINT8 *)&Cmd, CmdSize, ResultBuf, &ResultBufSize);
+ }
+
+ return Status;
+}
+
+
+#pragma optimize("",off)
+EFI_STATUS
+TpmHashLogExtendEventI(
+ IN UINT8 *DataToHash,
+ IN UINT64 Flags,
+ IN UINTN DataSize,
+ IN OUT TCG_PCR_EVENT_HDR *NewEventHdr,
+ IN UINT8 *NewEventData
+)
+{
+ EFI_STATUS Status;
+ TCG_DIGEST Out_Digest;
+ BOOLEAN isSha1 = GetHashPolicy();
+ UINT32 TempSize;
+ UINTN RequiredSpace=0;
+
+
+ TRACE(( TRACE_ALWAYS," TpmHashLogExtendEvent Entry \n"));
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(NewEventHdr->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ if(DataToHash!=NULL)
+ {
+ if(isSha1==0){
+ RequiredSpace = sizeof(TCG_PCR_EVENT_HDR) - sizeof(NewEventHdr->Digest)\
+ + sizeof(NewEventHdr->Digest.digest) + NewEventHdr->EventSize;
+ Status = SHA1HashAll( NULL, DataToHash, DataSize, &NewEventHdr->Digest );
+ TRACE(( TRACE_ALWAYS," SHA1HashAll Status = %r \n", Status));
+ if(EFI_ERROR(Status))return Status;
+ }else{
+ /* RequiredSpace = sizeof(TCG_PCR_EVENT_HDR) - sizeof(NewEventHdr->Digest)\
+ + sizeof(NewEventHdr->Digest.digestSha2) + NewEventHdr->EventSize;
+ Status = SHA2HashAll( NULL, DataToHash, DataSize, &NewEventHdr->Digest );
+ TRACE(( TRACE_ALWAYS," SHA2HashAll Status = %r \n", Status));
+ if(EFI_ERROR(Status))return Status;*/
+ }
+ }
+
+
+
+ if((RequiredSpace + LastEventPtr) > \
+ (TreeEventLogLocation + MAX_LOG_AREA_SIZE))return EFI_OUT_OF_RESOURCES;
+
+ Status = InternalTcg20CommonExtend(NULL,
+ NewEventHdr->PCRIndex,
+ &NewEventHdr->Digest,
+ &Out_Digest);
+
+ TRACE(( TRACE_ALWAYS," InternalTcg20CommonExtend Status = %r \n", Status));
+ if(EFI_ERROR(Status))return Status;
+
+ TRACE(( TRACE_ALWAYS," LastEntry = %x \n", LastEntry));
+ if(LastEntry == NULL) return EFI_ABORTED;
+
+ LastEventPtr = LastEntry;
+
+ if(isSha1 == 0){ //log event record
+ pBS->CopyMem(
+ (VOID*)(UINTN)LastEntry,
+ NewEventHdr,
+ sizeof(TCG_PCR_EVENT_HDR) -sizeof(NewEventHdr->Digest) - sizeof(UINT32));
+
+ TempSize = sizeof(TCG_PCR_EVENT_HDR) -sizeof(NewEventHdr->Digest) - sizeof(UINT32);
+
+ pBS->CopyMem(
+ (VOID*)(UINTN)(LastEntry + TempSize) ,
+ (UINT8 *)&NewEventHdr->Digest.digest,
+ sizeof(NewEventHdr->Digest.digest));
+
+ TempSize+=sizeof(NewEventHdr->Digest.digest);
+
+ }else{
+
+ /* pBS->CopyMem(
+ (VOID*)(UINTN)LastEntry,
+ NewEventHdr,
+ sizeof(TCG_PCR_EVENT_HDR) -sizeof(NewEventHdr->Digest) - sizeof(UINT32));
+
+ TempSize = sizeof(TCG_PCR_EVENT_HDR) -sizeof(NewEventHdr->Digest) - sizeof(UINT32);
+
+ pBS->CopyMem(
+ (VOID*)(UINTN)(LastEntry + TempSize) ,
+ (UINT8 *)&NewEventHdr->Digest.digestSha2,
+ sizeof(NewEventHdr->Digest.digestSha2));
+
+ TempSize+=sizeof(NewEventHdr->Digest.digestSha2);*/
+ return EFI_UNSUPPORTED;
+ }
+
+
+ pBS->CopyMem(
+ (VOID*)(UINTN)(LastEntry + TempSize) ,
+ (UINT8 *)&NewEventHdr->EventSize,
+ sizeof(UINT32));
+
+ pBS->CopyMem(
+ (VOID*)(UINTN)(LastEntry + TempSize + sizeof(UINT32)) ,
+ NewEventData,
+ NewEventHdr->EventSize);
+
+ TempSize+=sizeof(UINT32);
+ LastEntry = LastEventPtr + ((EFI_PHYSICAL_ADDRESS)(UINTN)(NewEventHdr->EventSize \
+ + TempSize));
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+TreeHashLogExtentEvent (
+ IN EFI_TREE_PROTOCOL *This,
+ IN UINT64 Flags,
+ IN EFI_PHYSICAL_ADDRESS DataToHash,
+ IN UINT64 DataToHashLen,
+ IN TrEE_EVENT *TreeEvent
+ )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ TCG_PCR_EVENT_HDR TcgEvent;
+
+ if((This == NULL ) || (DataToHash == 0) || (TreeEvent == NULL)) {
+ Status = EFI_INVALID_PARAMETER;
+ goto Exit;
+ }
+ else if(TreeEvent->Size < (TreeEvent->Header.HeaderSize + sizeof(UINT32))\
+ || (TreeEvent->Header.PCRIndex > 23)){
+ Status = EFI_INVALID_PARAMETER;
+ goto Exit;
+ }
+
+ TcgEvent.PCRIndex = TreeEvent->Header.PCRIndex;
+ TcgEvent.EventType = TreeEvent->Header.EventType;
+ TcgEvent.EventSize = TreeEvent->Size - sizeof(TrEE_EVENT_HEADER) \
+ -sizeof(UINT32);
+
+ Status = TpmHashLogExtendEventI(
+ (UINT8 *)(UINTN)DataToHash,
+ Flags,
+ (UINTN) DataToHashLen,
+ &TcgEvent,
+ (UINT8 *)&TreeEvent->Event
+ );
+
+Exit:
+
+ return Status;
+}
+
+
+EFI_STATUS
+TreeSubmitCommand (
+IN EFI_TREE_PROTOCOL *This,
+IN UINT32 InputParameterBlockSize,
+IN UINT8 *InputParameterBlock,
+IN UINT32 OutputParameterBlockSize,
+IN UINT8 *OutputParameterBlock
+ )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ UINT32 ReturnSize = 0;
+ UINT32 Size = 0;
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+
+ if (This == NULL || InputParameterBlock == NULL || OutputParameterBlock == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if(Tpm20FwDevice ==FALSE)
+ {
+ ReturnSize = OutputParameterBlockSize;
+
+ Status = TpmDevice->Init( TpmDevice );
+
+ InBuffer[0].Buffer = InputParameterBlock;
+ InBuffer[0].Size = InputParameterBlockSize;
+ OutBuffer[0].Buffer = OutputParameterBlock;
+ OutBuffer[0].Size = OutputParameterBlockSize;
+
+
+ TpmDevice->Transmit(TpmDevice,
+ sizeof (InBuffer) / sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer);
+
+ TpmDevice->Close(TpmDevice );
+ }else{
+
+ Size = OutputParameterBlockSize;
+ Status = CrbSubmitCmd(InputParameterBlock,
+ InputParameterBlockSize,
+ OutputParameterBlock,
+ &Size);
+ }
+
+ return Status;
+}
+
+
+
+static EFI_STATUS CopyTcgLog(
+ void )
+{
+ TCG_LOG_HOB *TcgLog = NULL;
+ void** DummyPtr;
+ EFI_GUID gEfiPeiLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+
+ TcgLog = (TCG_LOG_HOB*) LocateATcgHob(
+ pST->NumberOfTableEntries,
+ pST->ConfigurationTable,
+ &gEfiPeiLogHobGuid );
+
+ DummyPtr = &TcgLog;
+
+ if ( *DummyPtr == NULL )
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ TcgLog->TableMaxSize = MAX_LOG_AREA_SIZE;
+
+ pBS->CopyMem(
+ (UINT8 *)(UINTN)TreeEventLogLocation,
+ (((UINT8 *)TcgLog) + sizeof(TCG_LOG_HOB)),
+ TcgLog->TableSize
+ );
+
+ LastEntry = TreeEventLogLocation + TcgLog->TableSize;
+
+ return EFI_SUCCESS;
+}
+
+
+
+
+EFI_TREE_PROTOCOL mTreeProtocol = {
+ TreeGetCapability,
+ TreeGetEventLog,
+ TreeHashLogExtentEvent,
+ TreeSubmitCommand
+};
+
+AMI_INTERNAL_HLXE_PROTOCOL InternalLogProtocol = {
+ TpmHashLogExtendEventI
+};
+
+
+
+EFI_STATUS
+InstallTrEEProtocol(
+ IN EFI_HANDLE Handle
+ )
+{
+ EFI_STATUS Status;
+ EFI_GUID gEfiTrEEProtocolGuid = EFI_TREE_PROTOCOL_GUID;
+ EFI_GUID gEfiAmiHLXEGuid = AMI_PROTOCOL_INTERNAL_HLXE_GUID;
+
+ TRACE(( TRACE_ALWAYS," InstallTrEEProtocol \n"));
+ Status = pBS->InstallProtocolInterface (
+ &Handle,
+ &gEfiTrEEProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mTreeProtocol
+ );
+
+ Status = pBS->InstallProtocolInterface (
+ &Handle,
+ &gEfiAmiHLXEGuid,
+ EFI_NATIVE_INTERFACE,
+ &InternalLogProtocol
+ );
+
+ Status = pBS->AllocatePages(AllocateAnyPages,
+ EfiRuntimeServicesData,
+ EFI_SIZE_TO_PAGES(MAX_LOG_AREA_SIZE),
+ (UINT64*)(UINTN)&TreeEventLogLocation);
+
+ pBS->SetMem(
+ (VOID*)((UINTN)TreeEventLogLocation),
+ (UINTN)MAX_LOG_AREA_SIZE,
+ 0x00);
+
+ //locate PEI hob and copy to the TreeLogArea
+ Status = CopyTcgLog();
+
+ TRACE(( TRACE_ALWAYS," InstallTrEEProtocol Exit Status = %r \n", Status));
+ return Status;
+}
+
+
+
+
+VOID UpdateTpmDeviceASL(
+ IN EFI_EVENT ev,
+ IN VOID *ctx)
+{
+ ACPI_HDR *dsdt;
+ EFI_PHYSICAL_ADDRESS dsdtAddress=0;
+ static VOID *reg;
+ EFI_EVENT Event;
+ EFI_STATUS Status;
+ UINT64 Value;
+
+
+ //locate AcpiProtocol
+
+ Status = LibGetDsdt(&dsdtAddress, EFI_ACPI_TABLE_VERSION_ALL);
+ if (EFI_ERROR(Status)){
+ TRACE((TRACE_ALWAYS, "UpdateTpmDeviceASL::DSDT not found\n"));
+ if(Status == EFI_NOT_AVAILABLE_YET){
+ //set callback
+ Status = pBS->CreateEvent( EFI_EVENT_NOTIFY_SIGNAL,
+ EFI_TPL_DRIVER, UpdateTpmDeviceASL, &reg, &Event );
+
+ if(EFI_ERROR(Status)){
+ TRACE((TRACE_ALWAYS, "Unable to create Event..Exit(1)\n"));
+ return;
+ }
+ Status = pBS->RegisterProtocolNotify( &gEfiAcpiSupportGuid, Event, &reg );
+ }
+ return;
+ }
+
+ TRACE((TRACE_ALWAYS, "UpdateTpmDeviceASL::dsdtAddress %x \n", dsdtAddress));
+ dsdt = (ACPI_HDR*)dsdtAddress;
+
+ TRACE((TRACE_ALWAYS, "dsdt->Signature = %x \n", dsdt->Signature));
+
+ Value = 1;
+ Status=UpdateAslNameObject(dsdt, "TTDP", (UINT64)Value);
+ if (EFI_ERROR(Status)){
+ TRACE((TRACE_ALWAYS, "UpdateTpmDeviceASL::Failure setting ASL TTDP %r \n", Status));
+ return;
+ }
+
+ if(isTpm20CrbPresent()){
+ Value = 0;
+ }else{
+ Value = 1;
+ }
+
+ Status=UpdateAslNameObject(dsdt, "TTPF", (UINT64)Value);
+ if (EFI_ERROR(Status)){
+ TRACE((TRACE_ALWAYS, "UpdateTpmDeviceASL::Failure setting ASL value %r \n", Status));
+ }
+ return;
+}
+
+VOID ReadMORValue( );
+
+
+EFI_STATUS
+EFIAPI Tcg20DxeEntry(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ TCG_PLATFORM_SETUP_PROTOCOL *PolicyInstance;
+ EFI_GUID gPolicyguid = TCG_PLATFORM_SETUP_POLICY_GUID;
+ TCG_CONFIGURATION Config;
+
+ TRACE(( TRACE_ALWAYS," Tcg20DxeEntry \n"));
+ if(!IsTpm20Device()){
+ if(!isTpm20CrbPresent()){
+ TRACE(( TRACE_ALWAYS," isTpm20CrbPresent returned false \n"));
+ return EFI_UNSUPPORTED;
+ }
+ TRACE(( TRACE_ALWAYS," Tpm20FwDevice = TRUE \n"));
+ Tpm20FwDevice = TRUE;
+ }
+
+ if(Tpm20FwDevice == FALSE)
+ {
+ Status = pBS->LocateProtocol(
+ &gEfiTpmDeviceProtocolGuid,
+ NULL,
+ &TpmDevice);
+ }
+
+ Status = pBS->LocateProtocol (&gPolicyguid, NULL, &PolicyInstance);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ ReadMORValue();
+
+ MemCpy(&Config, &PolicyInstance->ConfigFlags, sizeof(TCG_CONFIGURATION));
+
+ if(Config.TpmSupport != 0){
+ Config.Tpm20Device = 1;
+ }else{
+ Config.Tpm20Device = 0;
+ PolicyInstance->UpdateStatusFlags(&Config, TRUE);
+ return EFI_SUCCESS;
+ }
+
+ PolicyInstance->UpdateStatusFlags(&Config, TRUE);
+
+ Status = InstallTrEEProtocol(ImageHandle);
+ if(EFI_ERROR(Status))return EFI_ABORTED;
+
+ //install binding protocol TrEE binding protocol
+ Tpm20DriverBinding.DriverBindingHandle = ImageHandle;
+ Tpm20DriverBinding.ImageHandle = ImageHandle;
+
+ Status = pBS->InstallMultipleProtocolInterfaces (
+ &Tpm20DriverBinding.DriverBindingHandle,
+ &gEfiDriverBindingProtocolGuid, &Tpm20DriverBinding,
+ &gEfiComponentNameProtocolGuid, &gComponentName,
+ &gEfiComponentName2ProtocolGuid, &gComponentName2,
+ NULL);
+
+ UpdateTpmDeviceASL(NULL, NULL);
+
+ return EFI_SUCCESS;
+}
diff --git a/Core/EM/TCG2/Common/TcgLegacy.c b/Core/EM/TCG2/Common/TcgLegacy.c
new file mode 100644
index 0000000..5453141
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgLegacy.c
@@ -0,0 +1,977 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgLegacy/TcgLegacy.c 2 6/14/14 12:35a Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 6/14/14 12:35a $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgLegacy/TcgLegacy.c $
+//
+// 2 6/14/14 12:35a Fredericko
+//
+// 1 4/21/14 2:17p Fredericko
+//
+// 1 10/08/13 12:04p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 3:07p Fredericko
+//
+// 1 7/10/13 5:56p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 7 4/05/11 8:06p Fredericko
+// TCG Legacy IO support changes
+//
+// 6 3/31/11 4:58p Fredericko
+// Changes for TCG_LEGACY support
+//
+// 5 3/29/11 1:28p Fredericko
+//
+// 4 3/28/11 3:38p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 3 7/14/10 2:56p Fredericko
+// Included logic to update the CSM16 Table checksum.
+//
+// 2 5/20/10 8:56a Fredericko
+// Included File Header
+// Code Beautification
+// EIP 37653
+//
+// 1 3/23/10 7:57p Fredericko
+//
+// 21 3/19/10 4:20p Fredericko
+// modified for legacy IO interface support
+//
+// 20 12/31/09 2:36p Fredericko
+// Update Location of BevBcv function after legacy init call
+//
+// 19 11/19/09 4:13p Fredericko
+// Update last event for legacy efi aspect of boot
+//
+// 18 11/09/09 5:26p Fredericko
+// Changes for Memory Leak EIP 28575
+//
+// 17 6/02/09 2:38p Fredericko
+//
+// 16 6/01/09 4:15p Fredericko
+// Changes added for TCM_SUPPORT
+//
+// 15 4/30/09 6:15p Fredericko
+// Updated Header Date
+//
+// 14 4/30/09 5:32p Fredericko
+// AMI company Header Address changes
+//
+// 13 4/03/09 6:13p Fredericko
+// Coding standard changes
+//
+// 12 3/05/09 2:59p Fredericko
+//
+// 11 2/05/09 5:23p Fredericko
+// Use Trace instead of Debug for debug messages, Removed EDK headers
+// included and "gbs" changed to "pBS"
+//
+// 10 2/27/08 5:52p Fredericko
+// Tcg Specification Compliance changes
+//
+// 9 9/26/07 2:45p Fredericko
+// Build in TRACE mode fixes
+//
+// 8 9/04/07 6:07p Fredericko
+// Changes made for new compiler swtich "\W4" to work
+//
+// 7 9/04/07 10:19a Fredericko
+// Measuring Embedded PciROM pointer fixes.
+//
+// 6 6/13/07 5:17p Fredericko
+// Function to read embedded option ROMS
+//
+// 5 11/03/06 6:34p Andriyn
+//
+// 4 8/15/06 9:28a Andriyn
+//
+// 3 6/22/06 3:03p Andriyn
+//
+// 2 6/20/06 7:13p Andriyn
+// Changes due to protocols moved to MiscFramework
+//
+// 1 6/20/06 5:58p Andriyn
+//**********************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgLegacy.c
+//
+// Description:
+// Contains functions that handle setting up the handoff between EFI and Legacy
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <EFI.h>
+#include "TcgLegacy.h"
+#include "token.h"
+#include "TCGMisc.h"
+#include <Protocol\LegacyRegion.h>
+#include "TcgCommon.h"
+#include "protocol\TcgService\TcgTcmService.h"
+#include "protocol\TcgService\TcgService.h"
+#include "protocol\TpmDevice\TpmDevice.h"
+#include <Protocol\FirmwareVolume.h>
+#include <Protocol\LegacyBios.h>
+#include <AmiDxeLib.h>
+#include <Tpm20Includes\TrEEProtocol.h>
+
+
+EFI_GUID gEfiAmiTcgWakeEventDataHobGuid = EFI_TCG_WAKE_EVENT_DATA_HOB_GUID;
+EFI_GUID gEfiAmiHobListGuid = TCG_EFI_HOB_LIST_GUID;
+EFI_GUID gEfiAmiTcgLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+EFI_GUID gEfiIntTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID;
+
+
+
+#define GUID_VARIABLE_DECLARATION( Variable, Guid ) extern EFI_GUID Variable
+EFI_GUID gEfiAmiTHobListGuid = TCG_EFI_HOB_LIST_GUID;
+
+#include "TcgPc.h"
+
+void* AllocateRTMemory (
+ UINTN size );
+
+EFI_GUID TCGLEGX16_FILE_GUID
+ = {0x142204e2, 0xc7b1, 0x4af9, 0xa7, 0x29, 0x92, 0x37, 0x58, 0xd9, 0x6d, 0x3};
+
+EFI_GUID TPM32_FILE_GUID =
+ {0xaa31bc6, 0x3379, 0x41e8, 0x82, 0x5a, 0x53, 0xf8, 0x2c, 0xc0, 0xf2, 0x54};
+
+EFI_GUID MPTPM_FILE_GUID
+ ={0x7d113aa9, 0x6280, 0x48c6, 0xba, 0xce, 0xdf, 0xe7, 0x66, 0x8e, 0x83, 0x7};
+
+EFI_GUID TCMLEGX16_FILE_GUID
+ = {0x1E753E16, 0xDCEF, 0x47d0, 0x9A, 0x38, 0x7A, 0xDE, 0xCD, 0xB9, 0x83, 0xED};
+
+EFI_GUID TCM32_FILE_GUID =
+ {0xB74E676E,0x3B2E, 0x483f, 0x94, 0x58, 0xC3, 0x78, 0xFE, 0x0A, 0xC6, 0x9F};
+
+
+EFI_GUID gEfiLegacyRegionProtocol = EFI_LEGACY_REGION_PROTOCOL_GUID;
+
+#define GET_HOB_TYPE( Hob ) ((Hob).Header->HobType)
+#define GET_HOB_LENGTH( Hob ) ((Hob).Header->HobLength)
+#define GET_NEXT_HOB( Hob ) ((Hob).Raw + GET_HOB_LENGTH( Hob ))
+#define END_OF_HOB_LIST( Hob ) (GET_HOB_TYPE( Hob ) == \
+ EFI_HOB_TYPE_END_OF_HOB_LIST)
+
+static TPM32HEADER * installedTpm32 = 0;
+static EFI_TCG_PROTOCOL * gTcgProtocol = 0;
+extern TCG_ACPI_TABLE mTcgAcpiTableTemplate;
+UINT8 Tpm20Support = 0;
+
+
+#define _CR( Record, TYPE,\
+ Field )((TYPE*) ((CHAR8*) (Record) - (CHAR8*) &(((TYPE*) 0)->Field)))
+
+#define TCG_DXE_PRIVATE_DATA_FROM_THIS( This ) \
+ _CR( This, TCG_DXE_PRIVATE_DATA, TcgServiceProtocol )
+
+#define TCM_DXE_PRIVATE_DATA_FROM_THIS( This ) \
+ _CR( This, TCM_DXE_PRIVATE_DATA, TcgServiceProtocol )
+
+typedef struct _TCG_DXE_PRIVATE_DATA
+{
+ EFI_TCG_PROTOCOL TcgServiceProtocol;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+} TCG_DXE_PRIVATE_DATA;
+
+typedef struct _TCM_DXE_PRIVATE_DATA
+{
+ EFI_TCM_PROTOCOL TcgServiceProtocol;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+} TCM_DXE_PRIVATE_DATA;
+
+#pragma pack (1)
+typedef struct _TCG_PCR_EVENT_HDR2 {
+ TCG_PCRINDEX PCRIndex;
+ TCG_EVENTTYPE EventType;
+} TCG_PCR_EVENT_HDR2;
+#pragma pack()
+
+EFI_TREE_PROTOCOL *TrEEProtocolInstance = NULL;
+#define MAX_LOG_AREA_SIZE (32 * 1024)
+
+
+#define SEG_ALIGNMENT 0x10
+
+
+void TcgLogEventProxy(
+ TCG_PCR_EVENT* data )
+{
+ UINT32 n;
+
+ gTcgProtocol->LogEvent( gTcgProtocol, data, &n, 0x01 );
+}
+
+void TreeLogEventProxy(
+ TCG_PCR_EVENT* data )
+{
+ return; //unsupported
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: linkTPMDriver
+//
+// Description: Establishes link used to synchronize change to the
+// LOG when done through the INT1A interface while DXE is still in
+// control.
+//
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+void linkTPMDriver(
+ IN OUT TPM32HEADER * tpm32,
+ IN EFI_TCG_PROTOCOL *tcgProtocol )
+{
+ TCG_LOG_HOB *TcgLog;
+ TCG_EFI_BOOT_SERVICE_CAPABILITY Cap;
+ EFI_PHYSICAL_ADDRESS EventLogLoc;
+ EFI_PHYSICAL_ADDRESS LastEv;
+ BOOLEAN IsTrancated;
+ EFI_STATUS Status;
+
+ gTcgProtocol = tcgProtocol;
+
+ tpm32->lastEventShadow = 0;
+ tpm32->ptrOnTPMFailue = 0;
+
+ if(Tpm20Support == 0)
+ {
+ tpm32->efi_log_event_ptr = (UINTN) (void*)(UINTN)TcgLogEventProxy;
+
+ gTcgProtocol->StatusCheck( gTcgProtocol, &Cap, NULL, &EventLogLoc, &LastEv );
+ TcgLog = (TCG_LOG_HOB*)(UINTN)EventLogLoc;
+ TcgLog--;
+
+ TRACE((TRACE_ALWAYS, "\n\n linkTPMDriver: TCGLOG( %x )\n", TcgLog));
+
+
+ tpm32->log.memptr = (UINT32)( UINTN ) EventLogLoc;
+ tpm32->log.dwSize = TcgLog->TableMaxSize;
+ tpm32->lastEventShadow = 0;
+ }else{
+ if(TrEEProtocolInstance ==NULL) return;
+
+ tpm32->efi_log_event_ptr = (UINTN) (void*)(UINTN)TreeLogEventProxy;
+
+ Status = TrEEProtocolInstance->GetEventLog(TrEEProtocolInstance, TREE_BOOT_HASH_ALG_SHA1,\
+ &EventLogLoc, &LastEv, &IsTrancated);
+ tpm32->lastEventShadow = 0;
+ tpm32->ptrOnTPMFailue = 0;
+
+ tpm32->log.memptr = (UINT32)( UINTN ) EventLogLoc;
+ tpm32->log.dwSize = MAX_LOG_AREA_SIZE;
+ tpm32->lastEventShadow = 0;
+
+ }
+}
+
+
+UINT32 CountEvents(EFI_PHYSICAL_ADDRESS TcgLog, UINTN Eventlast, UINT8 HashPolicy)
+{
+ TCG_PCR_EVENT_HDR2 *TcgLogNext = (TCG_PCR_EVENT_HDR2 *)TcgLog;
+ UINTN NextLoc =0;
+ UINT32 EventSize=0;
+ UINTN *ValidCheck;
+ UINTN *ValidCheckNext;
+ UINT32 EventCount=0;
+ UINTN i=0;
+
+ ValidCheck = (UINTN *)TcgLog;
+ ValidCheckNext = ValidCheck + 1;
+
+ if(TcgLogNext == NULL) return EventCount;
+ if((UINTN)ValidCheck > Eventlast) return EventCount;
+ if(*ValidCheck == 0 && *ValidCheckNext == 0)return EventCount;
+
+ if(HashPolicy == 0)
+ {
+ //return the location of the next log
+ while((UINTN)ValidCheck <= Eventlast)
+ {
+
+ ValidCheckNext = ValidCheck + 1;
+ if(*ValidCheck == 0 && *ValidCheckNext == 0)break;
+
+ if(TcgLogNext->PCRIndex < 0)break;
+ EventSize = *(UINT32 *)(((UINTN)TcgLogNext) + TPM_SHA1_160_HASH_LEN + sizeof(TCG_PCR_EVENT_HDR2));
+ NextLoc = (UINTN)(((UINTN)TcgLogNext)+ EventSize + sizeof(EventSize)+\
+ + TPM_SHA1_160_HASH_LEN + sizeof(TCG_PCR_EVENT_HDR2));
+
+ TcgLogNext = (TCG_PCR_EVENT_HDR2 *)NextLoc;
+ ValidCheck = (UINTN *)NextLoc;
+ EventCount+=1;
+
+ }
+ }else{
+ //unsupported SHA1 only for now
+ }
+
+ return (EventCount);
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: UnlinkTPM32fromEFI
+//
+// Description: Breaks the link that exist between TPM32 code and DXE TCG
+// driver. The established link was used to synchronize change to the
+// LOG when done through the INT1A interface while DXE is still in
+// control. Need to break this link one DXE driver is stoped or EFI
+// boots OS ( including calling INT19)
+//
+//
+// Input: IN EFI_EVENT Event,
+// IN VOID *Context
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS EFIAPI UnlinkTPM32fromEFI(
+ IN EFI_EVENT Event,
+ IN VOID *Context )
+{
+ TCG_LOG_HOB *TcgLog;
+ TPM32HEADER * tpm32 = (TPM32HEADER*)Context;
+ EFI_PHYSICAL_ADDRESS logStart, logLast;
+ TCG_EFI_BOOT_SERVICE_CAPABILITY TcgCapability;
+ BOOLEAN IsTrancated;
+ EFI_STATUS Status;
+ UINT32 FreeLogSize;
+ SHA1_PCR_EVENT *PtrtoLastEvent;
+
+ if ( installedTpm32 == 0 )
+ {
+ return EFI_SUCCESS;
+ }
+
+ if(Tpm20Support == 0)
+ {
+ ASSERT( installedTpm32 == tpm32 );
+ TRACE((TRACE_ALWAYS, "UnlinkTPM32fromEFI: TPM32( %x )\n", tpm32));
+ installedTpm32 = 0;
+
+ tpm32->lastEventShadow = 0;
+ tpm32->efi_log_event_ptr = 0;
+ Status = gTcgProtocol->StatusCheck( gTcgProtocol,
+ &TcgCapability,
+ NULL,
+ &logStart,
+ &logLast );
+
+ if ( EFI_ERROR( Status ))
+ {
+ tpm32->last = 0;
+ tpm32->freelog = 0;
+ return Status;
+ }
+ TcgLog = (TCG_LOG_HOB*)(UINTN)logStart;
+ TcgLog--;
+
+ tpm32->last = (UINT32)( UINTN ) ( logLast - logStart );
+ tpm32->TPMAcDeact = TcgCapability.TPMDeactivatedFlag;
+ tpm32->freelog = TcgLog->TableSize;
+ tpm32->nextevent = TcgLog->EventNum + 1;
+
+ tpm32->Tpm20Enabled = 0;
+ }else{
+
+ ASSERT( installedTpm32 == tpm32 );
+ TRACE((TRACE_ALWAYS, "UnlinkTPM32fromEFI: TPM32( %x )\n", tpm32));
+ installedTpm32 = 0;
+
+ if(TrEEProtocolInstance ==NULL) return EFI_SUCCESS;
+
+ Status = TrEEProtocolInstance->GetEventLog(TrEEProtocolInstance, TREE_BOOT_HASH_ALG_SHA1,\
+ &logStart, &logLast, &IsTrancated);
+ tpm32->lastEventShadow = 0;
+ tpm32->ptrOnTPMFailue = 0;
+
+ tpm32->lastEventShadow = 0;
+ tpm32->efi_log_event_ptr = 0;
+
+ tpm32->last = (UINT32)( UINTN ) ( logLast );
+ tpm32->TPMAcDeact = 0;
+ FreeLogSize = (UINT32)(logLast - logStart);
+ FreeLogSize += (sizeof(SHA1_PCR_EVENT)- 1);
+ PtrtoLastEvent = (SHA1_PCR_EVENT *)(logLast);
+ FreeLogSize += PtrtoLastEvent->EventSize;
+ tpm32->freelog = FreeLogSize;
+ tpm32->nextevent = CountEvents(logStart,logLast,0);
+ tpm32->Tpm20Enabled = 1;
+
+ }
+
+ return EFI_SUCCESS;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: GetRawImage
+//
+// Description: Loads binary from RAW section of main firwmare volume
+//
+//
+// Input: IN EFI_GUID *NameGuid,
+// IN OUT VOID **Buffer,
+// IN OUT UINTN *Size
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS GetRawImage(
+ IN EFI_GUID *NameGuid,
+ IN OUT VOID **Buffer,
+ IN OUT UINTN *Size )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE *HandleBuffer = 0;
+ UINTN HandleCount = 0;
+ UINTN i;
+ EFI_FIRMWARE_VOLUME_PROTOCOL *Fv;
+ UINT32 AuthenticationStatus;
+
+ Status = pBS->LocateHandleBuffer(
+ ByProtocol,
+ &gEfiFirmwareVolumeProtocolGuid,
+ NULL,
+ &HandleCount,
+ &HandleBuffer
+ );
+
+ if ( EFI_ERROR( Status ) || HandleCount == 0 )
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Find desired image in all Fvs
+ //
+ for ( i = 0; i < HandleCount; i++ )
+ {
+ Status = pBS->HandleProtocol(
+ HandleBuffer[i],
+ &gEfiFirmwareVolumeProtocolGuid,
+ &Fv
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ pBS->FreePool( HandleBuffer );
+ return EFI_LOAD_ERROR;
+ }
+
+ //
+ // Try a raw file
+ //
+ *Buffer = NULL;
+ *Size = 0;
+ Status = Fv->ReadSection(
+ Fv,
+ NameGuid,
+ EFI_SECTION_RAW,
+ 0,
+ Buffer,
+ Size,
+ &AuthenticationStatus
+ );
+
+ if ( !EFI_ERROR( Status ))
+ {
+ break;
+ }
+ }
+ pBS->FreePool( HandleBuffer );
+
+ if ( i >= HandleCount )
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ return EFI_SUCCESS;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: AllocateRTMemory
+//
+// Description: Allocates memory used by TCG Legacy code during run-time
+//
+//
+// Input: IN UINTN size
+//
+// Output: VOID*
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+void* AllocateRTMemory(
+ IN UINTN size )
+{
+ EFI_STATUS Status;
+ void * addr = 0;
+
+ Status = pBS->AllocatePool( EfiRuntimeServicesCode, size, &addr );
+ return addr;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: FindCompatibility16Table
+//
+// Description: This function identifies the validity of CSM16 binary by
+// searching "$EFI" and verifying table checksum and returs the
+// location of $EFI table
+//
+// Input:
+//
+// Output: EFI_COMPATIBILITY16_TABLE*
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_COMPATIBILITY16_TABLE* FindCompatibility16Table( )
+{
+ UINT8 *p = NULL, *p1 = NULL;
+ UINT32 *data32;
+ UINT32 count32;
+ UINT8 chksum, count8, tablelength;
+
+ //
+ // Find CSM16 entry point; "$EFI" is in E0000..FFFFF, 16 bytes aligned.
+ //
+ data32 = (UINT32*)(UINTN)0xE0000;
+
+ for ( count32 = 0; count32 < 0x8000; count32 += 4 )
+ {
+ if ( data32[count32] != 0x24454649 )
+ {
+ continue;
+ }
+ p = (UINT8*)((UINTN)data32 + (count32 << 2)); // Pointer to "$EFI"
+
+ //
+ // Verify the checksum
+ //
+ tablelength = ((EFI_COMPATIBILITY16_TABLE*)p)->TableLength;
+
+ for ( chksum = 0, count8 = 0, p1 = p; count8 < tablelength; count8++ )
+ {
+ chksum = chksum + *p1++;
+ }
+
+ if ( chksum == 0 )
+ {
+ break;
+ }
+ }
+
+ if ( count32 == 0x8000 )
+ {
+ return 0;
+ }
+
+ return ((EFI_COMPATIBILITY16_TABLE*)p);
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: GetTCGLegacyInterface
+//
+// Description: Loads legacy BIOS binary extensions (TcgLegX16,
+// TPM32 and MPTPM ) and initializes the TCG Legacy support.
+//
+// Input: IN EFI_HANDLE ImageHandle,
+// IN EFI_SYSTEM_TABLE *SystemTable
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS InitTCGLegacyInterface(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ TCG_LEGX16_HEADER *legX16header;
+ void * legX16dest;
+ UINTN legX16size;
+ EFI_LEGACY_BIOS_PROTOCOL *legBios;
+ void * rawPtr;
+ static TpmBinaryStruct tpmBinary;
+ UINT16 segLegX16;
+ TPM32HEADER * tpm32hdr;
+ UINTN tpm32size;
+ TPMBIOSDriverHeader * mptpmHdr;
+#if TCG_LEGACY == 0
+ UINTN mpTpmSize;
+#endif
+ EFI_TCG_PROTOCOL *tcgProtocol;
+ EFI_EVENT event;
+ EFI_LEGACY_REGION_PROTOCOL * iRegion;
+ EFI_GUID gMpDriverHobGuid = EFI_TCG_MPDriver_HOB_GUID;
+ FAR32LOCALS *LegFill = NULL;
+ void *Table = NULL;
+ UINTN TableSize = 0;
+ UINTN Location = 0;
+ UINTN Alignment = 0;
+ EFI_GUID gEfiTrEEProtocolGuid = EFI_TREE_PROTOCOL_GUID;
+
+ InitAmiLib( ImageHandle, SystemTable );
+
+ if ( installedTpm32 != 0 )
+ {
+ ASSERT( installedTpm32 == 0 );
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Access EFI TPM driver
+ //
+ Status = pBS->LocateProtocol( &gEfiIntTcgProtocolGuid, NULL,
+ &tcgProtocol );
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS, "TCG Service is not found: error=%x\n", Status));
+ tcgProtocol = 0;
+ Status = pBS->LocateProtocol( &gEfiTrEEProtocolGuid, NULL, &TrEEProtocolInstance );
+ if(EFI_ERROR(Status))return Status;
+ Tpm20Support = 1;
+ }
+
+
+ //
+ // Access legacyBios internals
+ //
+ EFI_VERIFY(
+ Status = pBS->LocateProtocol(
+ &gEfiLegacyBiosProtocolGuid,
+ NULL,
+ &legBios
+ ));
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+#if TCG_LEGACY == 0
+ if(AutoSupportType()){
+ TCGLEGX16_FILE_GUID = TCMLEGX16_FILE_GUID;
+ TPM32_FILE_GUID = TCM32_FILE_GUID;
+ }
+#else
+ TCGLEGX16_FILE_GUID = TCMLEGX16_FILE_GUID;
+ TPM32_FILE_GUID = TCM32_FILE_GUID;
+#endif
+
+
+ //
+ // Load LEGX16 into legacy region
+ //
+ rawPtr = 0;
+ Status = GetRawImage( &TCGLEGX16_FILE_GUID, &rawPtr, &legX16size );
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS, "Failed to load LEGX16: error=%x\n", Status));
+ return Status;
+ }
+ legX16header = (TCG_LEGX16_HEADER* )rawPtr;
+ EFI_VERIFY(
+ legBios->GetLegacyRegion( legBios, legX16size + SEG_ALIGNMENT, 0,
+ SEG_ALIGNMENT, &legX16dest ));
+ segLegX16 = (UINT16)((UINTN)legX16dest >> 4 );
+
+ //
+ // Load TPM32 into runtime-code memory
+ //
+ Status = GetRawImage( &TPM32_FILE_GUID, &rawPtr, &tpm32size );
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS, "Failed to load TPM32: error=%x\n", Status));
+ return Status;
+ }
+ tpm32hdr = AllocateRTMemory( tpm32size );
+ MemCpy( tpm32hdr, rawPtr, tpm32size );
+
+ //
+ // Load MPTPM into runtime-code memory
+ //
+#if TCG_LEGACY == 0
+ if(!(AutoSupportType())){
+ Status = GetRawImage( &MPTPM_FILE_GUID, &rawPtr, &mpTpmSize );
+
+ if ( EFI_ERROR( Status )){
+ TRACE((TRACE_ALWAYS, "Failed to load MPTPM: error=%x\n", Status));
+ return Status;
+ }
+ mptpmHdr = AllocateRTMemory( mpTpmSize );
+ MemCpy( mptpmHdr, rawPtr, mpTpmSize );
+ }else{
+ LegFill = (FAR32LOCALS*)LocateATcgHob( pST->NumberOfTableEntries,
+ pST->ConfigurationTable,
+ &gMpDriverHobGuid );
+ mptpmHdr = (TPMBIOSDriverHeader*)(UINTN)( LegFill->Offset - LegFill->Codep );
+ }
+#else
+ LegFill = (FAR32LOCALS*)LocateATcgHob( pST->NumberOfTableEntries,
+ pST->ConfigurationTable,
+ &gMpDriverHobGuid );
+ mptpmHdr = (TPMBIOSDriverHeader*)(UINTN)( LegFill->Offset - LegFill->Codep );
+#endif
+
+
+
+ //
+ // Link pointers from TPM32 to MPTPM
+ //
+ tpm32hdr->MP_HDR = (UINT32)( UINTN ) mptpmHdr;
+ tpm32hdr->scratch.memptr = (UINT32)( UINTN ) AllocateRTMemory(
+ TPM32_SCRATCHMEM_SIZE );
+ tpm32hdr->scratch.dwSize = TPM32_SCRATCHMEM_SIZE;
+ {
+ UINT32 * p
+ = (UINT32*)((UINT8*)legX16header + legX16header->wTpm32entryPtr);
+ *p = (UINT32)( UINTN ) tpm32hdr + tpm32hdr->entryPoint;
+ }
+ legX16header->wTpm32hdr = (UINT32)( UINTN ) tpm32hdr;
+ linkTPMDriver( tpm32hdr, tcgProtocol );
+ legX16header->regMOR = ((TCG_MOR_REG) << 8);
+
+ //
+ // Copy final LegX16 to dest (F000-E000 area)
+ //
+ legBios->CopyLegacyRegion( legBios, legX16size, legX16dest, legX16header );
+ legX16header = (TCG_LEGX16_HEADER* )legX16dest;
+
+
+ //
+ // Unlock E000-F000: Init will update variable inside LEGX16
+ //
+ Status = pBS->LocateProtocol( &gEfiLegacyRegionProtocol, NULL, &iRegion );
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS,
+ "Failed to locate Legacy Region Protocol to unlock E000: %r\n",
+ Status));
+ return Status;
+ }
+ Status = iRegion->UnLock( iRegion, 0xE0000, 0x20000, NULL );
+
+ //
+ // Init LEGX16
+ //
+ {
+ EFI_IA32_REGISTER_SET Regs;
+
+ if ( EFI_ERROR( Status ))
+ {
+ TRACE((TRACE_ALWAYS, "Failed to unlock Legacy region E000: %r\n",
+ Status));
+ return Status;
+ }
+
+ MemSet( &Regs, sizeof (EFI_IA32_REGISTER_SET), 0 );
+ legBios->FarCall86(
+ legBios,
+ segLegX16,
+ legX16header->InitCode,
+ &Regs,
+ NULL,
+ 0
+ );
+ }
+
+ //
+ // Lock E000-F000
+ //
+ iRegion->Lock( iRegion, 0xE0000, 0x20000, NULL );
+
+ //
+ // Fills TpmBinaryStruct : Setup int1Ahook, int19Hook, and osloaderHook
+ //
+ tpmBinary.wLegX16Seg = segLegX16;
+ tpmBinary.int1a_dispatch = legX16header->int1a_dispatch;
+ tpmBinary.int19Ev = legX16header->int19Ev;
+ tpmBinary.intLoaderEv = legX16header->intLoaderEv;
+ tpmBinary.BevBcvEv = legX16header->BevBcvEv;
+
+ //
+ // Hookup for BootimeServices shutdown: need to strip *installedTpm32 off the
+ // pointers to BootTime data
+ //
+ installedTpm32 = tpm32hdr;
+
+ #if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT) && EFI_SPECIFICATION_VERSION <\
+ 0x20000
+ EFI_VERIFY(
+ Status = gBS->CreateEvent( EFI_EVENT_SIGNAL_LEGACY_BOOT,
+ EFI_TPL_CALLBACK, UnlinkTPM32fromEFI,
+ tpm32hdr, &event ));
+ #else
+ EFI_VERIFY(
+ Status = CreateLegacyBootEvent(
+ EFI_TPL_CALLBACK,
+ UnlinkTPM32fromEFI,
+ tpm32hdr,
+ &event
+ ));
+ #endif
+ TRACE((TRACE_ALWAYS, "\tLEGX16: %x:%x, %x, %x\n",
+ tpmBinary.wLegX16Seg, tpmBinary.int1a_dispatch, tpmBinary.int19Ev,
+ tpmBinary.intLoaderEv));
+ TRACE((TRACE_ALWAYS, "\tTPM32: header:%x entry:%x log:%x logsize:%x\n",
+ (UINT32)( UINTN ) tpm32hdr, (UINT32)( UINTN ) tpm32hdr
+ + tpm32hdr->entryPoint));
+ TRACE((TRACE_ALWAYS, "\tMPTPM: %x\n", (UINT32)( UINTN ) mptpmHdr));
+
+ //
+ // Returns table pointing to TpmBinaryStruct
+ //
+ if ( Table != NULL && TableSize != NULL )
+ {
+ Table = &tpmBinary;
+ TableSize = (UINTN)sizeof(tpmBinary);
+
+ if ( Location )
+ {
+ Location = 0;
+ }
+
+ if ( Alignment )
+ {
+ Alignment = SEG_ALIGNMENT;
+ }
+ }
+ else {
+ //
+ // Put them int Leg Segment on our own
+ //
+ void * legPtr = 0;
+ EFI_COMPATIBILITY16_TABLE * bfi16 = 0;
+ UINT8 * p;
+ UINT8 chksum;
+ UINT8 i=0;
+
+ EFI_VERIFY(
+ legBios->GetLegacyRegion( legBios, sizeof(tpmBinary)
+ + SEG_ALIGNMENT, 0,
+ SEG_ALIGNMENT, &legPtr ));
+ Status = iRegion->UnLock( iRegion, 0xE0000, 0x20000, NULL );
+ MemCpy( legPtr, &tpmBinary, sizeof(tpmBinary));
+ bfi16 = FindCompatibility16Table( );
+
+ if ( bfi16 != 0 )
+ {
+ TRACE((TRACE_ALWAYS, "\tFound BFI at 0x%x\n", bfi16));
+ bfi16->TpmSegment = (UINT16)((UINTN)legPtr >> 4 );
+ bfi16->TpmOffset = 0;
+
+ bfi16->TableChecksum = 0;
+ p = (UINT8*)bfi16;
+ for (chksum=0, i=0; i<bfi16->TableLength; i++) {
+ chksum+=*p++;
+ }
+ bfi16->TableChecksum = ~(--chksum);
+ }
+
+
+ else {
+ TRACE((TRACE_ALWAYS, "\t!!!Not Found BFI\n"));
+ }
+ iRegion->Lock( iRegion, 0xE0000, 0x20000, NULL );
+ }
+
+
+ return EFI_SUCCESS;
+}
+
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Core/EM/TCG2/Common/TcgLegacy.cif b/Core/EM/TCG2/Common/TcgLegacy.cif
new file mode 100644
index 0000000..b2a318f
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgLegacy.cif
@@ -0,0 +1,12 @@
+<component>
+ name = "TcgLegacy"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common"
+ RefName = "TcgLegacy"
+[files]
+"TcgLegacy.sdl"
+"TcgLegacy.mak"
+"TcgLegacy.c"
+"TcgLegacy.h"
+"TcgLegacy.dxs"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/TcgLegacy.dxs b/Core/EM/TCG2/Common/TcgLegacy.dxs
new file mode 100644
index 0000000..d238b69
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgLegacy.dxs
@@ -0,0 +1,71 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgLegacy/TcgLegacy.dxs 1 4/21/14 2:17p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:17p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgLegacy/TcgLegacy.dxs $
+//
+// 1 4/21/14 2:17p Fredericko
+//
+// 1 10/08/13 12:04p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 3:09p Fredericko
+//
+// 1 7/10/13 5:56p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 5/20/10 8:58a Fredericko
+// Included File Header
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgLEgacy.dxs
+//
+// Description:
+// dependecy file
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Protocol/TcgService/TcgService.h>
+#include <Protocol/LegacyBios.h>
+
+DEPENDENCY_START
+ EFI_LEGACY_BIOS_PROTOCOL_GUID
+DEPENDENCY_END
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//********************************************************************** \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/TcgLegacy.h b/Core/EM/TCG2/Common/TcgLegacy.h
new file mode 100644
index 0000000..51e3fad
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgLegacy.h
@@ -0,0 +1,213 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgLegacy/TcgLegacy.h 1 4/21/14 2:17p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:17p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgLegacy/TcgLegacy.h $
+//
+// 1 4/21/14 2:17p Fredericko
+//
+// 1 10/08/13 12:04p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 3:08p Fredericko
+//
+// 1 7/10/13 5:56p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 5/20/10 8:57a Fredericko
+// Included File Header
+// Code Beautification
+// EIP 37653
+//
+// 1 3/23/10 7:57p Fredericko
+//
+// 11 12/31/09 2:42p Fredericko
+// modfied the legacy16 and tpm32 structure.
+//
+// 10 4/30/09 6:16p Fredericko
+// Updated Header Date
+//
+// 9 4/30/09 5:33p Fredericko
+// AMI company Header Address changed
+//
+// 8 3/05/09 3:17p Fredericko
+// Changes for CoreSources dependency
+//
+// 7 2/27/08 5:53p Fredericko
+// Change in tpm32Header
+//
+// 6 6/13/07 5:24p Fredericko
+// Function header for GetPCIOptionROM added
+//
+// 5 11/30/06 5:00p Fasihm
+// More organized and formatted.
+//
+// 4 8/25/06 4:10p Andriyn
+// Changed LEGX16HEADER with fields to track version information
+//
+// 3 8/22/06 1:30p Andriyn
+// MOR related changes
+//
+// 2 8/15/06 9:28a Andriyn
+//
+// 1 6/20/06 5:58p Andriyn
+//**********************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgLegacy.h
+//
+// Description:
+// Header file for TCG Legacy subcomponent
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <EFI.h>
+
+#pragma pack (push, 1)
+
+EFI_FORWARD_DECLARATION( EFI_LEGACY_TCG_PROTOCOL );
+
+typedef struct _TCG_LEGX16_HEADER TCG_LEGX16_HEADER;
+struct _TCG_LEGX16_HEADER
+{
+ UINT16 wHeaderSize;
+ UINT16 wLeg16Ver;
+ UINT32 wTpm32hdr;
+ UINT16 wTpm32entryPtr;
+ UINT16 int1a_dispatch;
+ UINT16 int19Ev;
+ UINT16 intLoaderEv;
+ UINT16 BevBcvEv;
+ UINT16 InitCode;
+ UINT16 Reserved;
+ UINT16 regMOR; //8-15: byte offset; 0-7: bit position
+};
+
+typedef struct _TpmBinaryStruct TpmBinaryStruct;
+struct _TpmBinaryStruct
+{
+ UINT16 wLegX16Seg;
+ UINT16 int1a_dispatch;
+ UINT16 int19Ev;
+ UINT16 intLoaderEv;
+ UINT16 BevBcvEv;
+};
+
+typedef struct _TPMBIOSDriverHeader TPMBIOSDriverHeader;
+struct _TPMBIOSDriverHeader
+{
+ UINT16 TPMSignature; // 55AAh
+ UINT32 TPMCodeOffset; // Offset to Entry Point
+ UINT16 TPMCodeSize;
+ UINT32 TPMBaseAddr; // Base Adress of CMD register
+ UINT32 TPMBaseAddrOpt;
+ UINT8 TPMIRQ;
+ UINT8 TPMDMA;
+ UINT8 TPMCheckSum;
+ UINT8 TPMReserve1; // 00h
+ UINT32 TPMPCIPFA;
+ UINT32 TPMUSB;
+ UINT32 TPMReserve2; // 00000000h
+ UINT16 TPMOEM0;
+ UINT16 TPMOEM1;
+};
+
+typedef struct _MEM_OBJECT MEM_OBJECT;
+struct _MEM_OBJECT
+{
+ UINT32 memptr; //void* memptr;
+ UINT32 dwSize;
+ UINT32 reserved1;
+};
+
+typedef struct _TPM32HEADER TPM32HEADER;
+struct _TPM32HEADER
+{
+ UINT32 Signature; //Signature of TPM32 module
+ UINT32 entryPoint; //offset to the dispatch code relative to the
+ //start of the TPM32 module
+ UINT32 MP_HDR; //TPMBIOSDriverHeader* MP_HDR;//offset to the start of the MP driver in MP_xSEG
+ MEM_OBJECT scratch;
+
+ //errType is one of { TCPA_ERRGRP_TPM,TCPA_ERRGRP_TCPA,or TCPA_ERRGRP_OTHER}
+ //see tcpatpm.inc
+ UINT32 errType;
+ UINT8 TPMAcDeact;
+ //meaning of errCode depends on errType: TPM err code, TCPA err code
+ //or own error code
+ UINT32 errCode;
+
+ UINT32 ptrOnTPMFailue;
+
+ MEM_OBJECT log;
+ UINT32 freelog;
+ UINT32 last;
+ UINT32 nextevent;
+ UINT32 lastEventShadow; // UINT8**
+ UINT8 Tpm20Enabled;
+ UINT64 efi_log_event_ptr;
+};
+
+typedef struct _SHA1_TCG_PCR_EVENT {
+ UINT32 PCRIndex; // PCRIndex event extended to
+ UINT32 EventType; // TCG EFI event type
+ UINT8 Digest[20]; // Value extended into PCRIndex
+ UINT32 EventSize; // Size of the event data
+ UINT8 Event[1]; // The event data
+} SHA1_PCR_EVENT;
+
+#pragma pack (pop)
+//
+// TcgLegacy imports
+//
+EFI_STATUS GetRawImage (
+ IN EFI_GUID *NameGuid,
+ IN OUT VOID **Buffer,
+ IN OUT UINTN *Size );
+
+EFI_STATUS GetPCIOPROMImage (
+ IN EFI_HANDLE PciHandle,
+ OUT VOID *RomImage,
+ OUT UINTN *Romsize,
+ OUT UINTN *Flags );
+#ifdef EFI_DEBUG
+ #define EFI_VERIFY( x ) ASSERT( !EFI_ERROR( x ))
+#else
+ #define EFI_VERIFY( x ) x
+#endif
+#define TPM32_SCRATCHMEM_SIZE 0x400
+#define TPM32_LOG_SIZE 0x1000
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Core/EM/TCG2/Common/TcgLegacy.mak b/Core/EM/TCG2/Common/TcgLegacy.mak
new file mode 100644
index 0000000..ce91db5
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgLegacy.mak
@@ -0,0 +1,104 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+#*************************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgLegacy/TcgLegacy.mak 1 4/21/14 2:17p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:17p $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgLegacy/TcgLegacy.mak $
+#
+# 1 4/21/14 2:17p Fredericko
+#
+# 1 10/08/13 12:04p Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 1 7/10/13 5:56p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+#
+# 5 4/22/11 8:54p Fredericko
+# Changes for x32bit mode build
+#
+# 4 3/29/11 1:28p Fredericko
+#
+# 3 3/28/11 3:38p Fredericko
+# [TAG] EIP 54642
+# [Category] Improvement
+# [Description] 1. Checkin Files related to TCG function override
+# 2. Include TCM and TPM auto detection
+# [Files] Affects all TCG files
+#
+# 2 5/20/10 8:55a Fredericko
+# Included File Header
+# Included File Revision History
+# EIP 37653
+#
+#*************************************************************************
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: tcgLegacy.MAK
+#
+# Description:
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+all: TcgLegacy
+
+TcgLegacy : $(BUILD_DIR)\TcgLegacy.mak TcgLegacyBIN
+
+$(BUILD_DIR)\TcgLegacy.mak : $(TCGLEG_DIR)\TcgLegacy.cif $(TCGLEG_DIR)\TcgLegacy.mak $(BUILD_RULES)
+ $(CIF2MAK) $(TCGLEG_DIR)\TcgLegacy.cif $(CIF2MAK_DEFAULTS)
+
+TcgLegacyCflags=$(CFLAGS)\
+ /I$(TCG_DIR)\
+ /I$(TPM12_DIR)\
+ /I$(TCG_DIR)\Common\
+
+!IFNDEF LIB_BUILD_DIR
+!IF "$(PROCESSOR)"=="x64"
+AMITCMLIB = $(BUILD_DIR)\IA32\AmiTcmlib.lib
+!ELSE
+AMITCMLIB = $(BUILD_DIR)\AmiTcmlib.lib
+!ENDIF
+!ENDIF #LIB_BUILD_DIR
+
+
+TcgLegacyBIN: $(AMIDXELIB) $(AMITCMLIB) $(BUILD_DIR)\AmiTcgLibDxe.lib
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TcgLegacy.mak all\
+ "CFLAGS=$(TcgLegacyCflags)"\
+ "CPFLAGS=$(TcgLegacyCflags)"\
+ GUID=858EBE6F-360F-415b-B7DC-463AAEB03412 \
+ ENTRY_POINT=InitTCGLegacyInterface\
+ TYPE=BS_DRIVER \
+ COMPRESS=1\
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
diff --git a/Core/EM/TCG2/Common/TcgLegacy.sdl b/Core/EM/TCG2/Common/TcgLegacy.sdl
new file mode 100644
index 0000000..c6de6fe
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgLegacy.sdl
@@ -0,0 +1,36 @@
+TOKEN
+ Name = "TcgLegacy_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable TcgLegacy support in Project"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Master = Yes
+ Token = "CSM_SUPPORT" "=" "1"
+End
+
+PATH
+ Name = "TCGLEG_DIR"
+End
+
+MODULE
+ Help = "Includes TcgLegacy.mak to Project"
+ File = "TcgLegacy.mak"
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\TcgLegacy.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End
+
+TOKEN
+ Name = "TCG_MOR_REG"
+ Value = "0xE3"
+ Help = "Address of the MOR bit in CMOS (byte location in the bank of CMOS registers)"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/TcgPei.cif b/Core/EM/TCG2/Common/TcgPei.cif
new file mode 100644
index 0000000..013895b
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPei.cif
@@ -0,0 +1,18 @@
+<component>
+ name = "TcgPei"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common"
+ RefName = "TcgPei"
+[files]
+"TcgPei.mak"
+"TisPei.c"
+"TcgPei.dxs"
+"TcgTisPei.c"
+"xTcgPei.c"
+"TcgTcmPei.c"
+"EMpTcmPei.c"
+"TcgCRBPei.c"
+"TcgPei.sdl"
+[parts]
+"TcgPeiAfterMem"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/TcgPei.dxs b/Core/EM/TCG2/Common/TcgPei.dxs
new file mode 100644
index 0000000..d4726c4
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPei.dxs
@@ -0,0 +1,114 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPei.dxs 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPei.dxs $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 11 3/29/11 12:57p Fredericko
+//
+// 10 3/28/11 2:10p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 9 5/19/10 5:45p Fredericko
+// Included File Header
+// Updated AMI copyright header
+// EIP 37653
+//
+// 8 6/01/09 4:23p Fredericko
+//
+// 7 4/30/09 6:21p Fredericko
+// Updated Header Date
+//
+// 6 4/30/09 5:41p Fredericko
+// AMI company Header Address changed
+//
+// 5 2/05/09 5:43p Fredericko
+// No more using EDK style includes
+//
+// 4 6/25/08 6:17p Fredericko
+// Txt related changes
+//
+// 3 6/02/08 8:37p Fredericko
+//
+// 2 6/22/06 3:03p Andriyn
+//
+// 1 6/20/06 5:58p Andriyn
+//
+// 4 3/03/06 5:18p Markw
+// Added checking boot mode.
+//
+// 3 2/03/06 10:30a Markw
+// This is loaded after memory.
+//
+// 2 10/05/05 4:38p Mirk
+// All changes based on P4 CPU label "1.00.18_INTEL_P4_05"
+//
+// 3 9/07/05 11:55a Markw
+// Added dependency on read only variable for setup.
+//
+//**********************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgPei.dxs
+//
+// Description:
+// Dependency file for TcgPei subcomponent
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <pei.h>
+#include "ppi\LoadFile.h"
+#include <Ppi\ReadOnlyVariable.h>
+#include <token.h>
+
+
+DEPENDENCY_START
+ EFI_PEI_MASTER_BOOT_MODE_PEIM_PPI AND
+ EFI_PEI_READ_ONLY_VARIABLE_PPI_GUID
+DEPENDENCY_END
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/TcgPei.mak b/Core/EM/TCG2/Common/TcgPei.mak
new file mode 100644
index 0000000..99e7323
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPei.mak
@@ -0,0 +1,123 @@
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#*************************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPei.mak 1 4/21/14 2:16p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:16p $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPei.mak $
+#
+# 1 4/21/14 2:16p Fredericko
+#
+# 1 10/08/13 12:02p Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 2 10/03/13 1:51p Fredericko
+#
+# 1 7/10/13 5:51p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+#
+# 27 10/24/11 12:39p Fredericko
+# WAIT_FOR_MEM token is deprecated. Use the StartupCmd_Selftest_State to
+# control when TPM is first used.
+#
+# 26 9/27/11 10:20p Fredericko
+# [TAG] EIP67286
+# [Category] Improvement
+# [Description] changes for Tcg Setup policy
+# [Files] Tcg.sdl
+# TcgPei.cif
+# TcgPei.mak
+# xtcgPei.c
+# xTcgPeiAfterMem.c
+# TcgPeiAfterMem.mak
+# TcgDxe.cif
+# TcgDxe.mak
+# xTcgDxe.c
+# AmiTcgPlatformPeilib.c
+# AmiTcgPlatformDxelib.c
+#
+# 25 4/22/11 8:49p Fredericko
+# Changes for building in x32 bit mode.
+#
+# 24 3/29/11 12:56p Fredericko
+#
+# [TAG] EIP 54642
+# [Category] Improvement
+# [Description] 1. Checkin Files related to TCG function override
+# 2. Include TCM and TPM auto detection
+# [Files] Affects all TCG files
+#
+#
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: TCGPEI.MAK
+#
+# Description: Make file for the TcgPei component
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+all : tcgPei
+
+tcgPei : $(BUILD_DIR)\TcgPei.mak TcgPeiBin
+
+$(BUILD_DIR)\TcgPei.mak : $(TCGPEI_DIR)\$(@B).cif $(TCGPEI_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(TCGPEI_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+TCGPEI_CFLAGS=$(CFLAGS)\
+ /I$(TcgPlatformSetupPeiPolicy_DIR)\
+ /I$(TCG_DIR)\
+ /I$(TPM12_DIR)\
+ /I$(TPM20_CRBLIB)\
+ /I$(TCG_DIR)\Common\
+ /I$(TCG_BOARD_OEM__DIR)\
+
+!IFNDEF LIB_BUILD_DIR
+!IF "$(PROCESSOR)"=="x64"
+TCGLIB=$(BUILD_DIR)\IA32\TisLib.lib
+!ELSE
+TCGLIB=$(BUILD_DIR)\TisLib.lib
+!ENDIF
+!ENDIF #LIB_BUILD_DIR
+
+TcgPeiBin : $(AMIPEILIB) $(BUILD_DIR)\AmiTcgLibPei.lib $(BUILD_DIR)\IA32\Tpm20CRBLib.lib
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TcgPei.mak all\
+ "CFLAGS=$(TCGPEI_CFLAGS) "\
+ GUID=34989D8E-930A-4a95-AB04-2E6CFDFF6631\
+ ENTRY_POINT=CommonTcgPeiEntryPoint \
+ TYPE=PEIM \
+ DEPEX1=$(TCGPEI_DIR)\TcgPei.dxs \
+ DEPEX1_TYPE=EFI_SECTION_PEI_DEPEX \
+ EXT_HEADERS=$(BUILD_DIR)\token.h \
+ COMPRESS=1\
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
diff --git a/Core/EM/TCG2/Common/TcgPei.sdl b/Core/EM/TCG2/Common/TcgPei.sdl
new file mode 100644
index 0000000..445a5a2
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPei.sdl
@@ -0,0 +1,34 @@
+TOKEN
+ Name = "TcgPeiSupport"
+ Value = "1"
+ Help = "Enable or Diasble TcgPeiSupport"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetH = Yes
+ TargetMAK = Yes
+ Master = Yes
+ Token = "TCG2Support" "=" "1"
+End
+
+PATH
+ Name = "TCGPEI_DIR"
+End
+
+MODULE
+ Help = "Includes tcgpei.mak into project"
+ Path = "$(TCGPEI_DIR)"
+ File = "tcgpei.mak"
+End
+
+MODULE
+ Help = "Includes tcgpei.mak into project"
+ Path = "$(TCGPEI_DIR)"
+ File = "TcgPeiAftermem.mak"
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\tcgPei.ffs"
+ Parent = "$(BUILD_DIR)\TcgPlatformSetupPeiPolicy.ffs"
+ InvokeOrder = AfterParent
+End
+
diff --git a/Core/EM/TCG2/Common/TcgPeiAfterMem.c b/Core/EM/TCG2/Common/TcgPeiAfterMem.c
new file mode 100644
index 0000000..cc659e6
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPeiAfterMem.c
@@ -0,0 +1,492 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TcgPei.c
+
+ Abstract:
+
+ PEIM that provides TCG services
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPeiAfterMem/TcgPeiAfterMem.c 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPeiAfterMem/TcgPeiAfterMem.c $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 1:57p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 1/12/12 12:11p Fredericko
+// Remove unused function.
+//
+// 2 8/29/11 6:49p Fredericko
+// [TAG] EIP0000
+// [Category] Improvement
+// [Description] Include Open and Close of locality 0 for TPM Ppi
+// functions
+// [Files] TcgPeiAfterMem.c
+//
+// 1 8/22/11 1:45p Fredericko
+// [TAG] EIP61168
+// [Category] Improvement
+// [Description] Reload TCG PPI from memory when Memory is Installed
+// [Files] TcgPeiAfterMem.cif
+// TcgPeiAfterMem.c
+// xTcgPeiAfterMem.c
+// TcgPeiAfterMem.mak
+//
+// 54 3/31/11 4:49p Fredericko
+// Changes for TCG_LEGACY support
+//
+// 53 3/29/11 12:57p Fredericko
+//
+// 52 3/28/11 2:12p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 50 8/04/10 5:16p Fredericko
+// Changes to flow of Lock Physical Presence for support Smi PPI changes
+//
+// 49 5/21/10 4:31p Fredericko
+// Changes for some build errors that happened with MOR support
+//
+// 48 5/19/10 5:51p Fredericko
+// Updated AMI Function Headers
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgPei.c
+//
+// Description:
+// Functions for early initialization of TPM are executed here
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include "TcgCommon.h"
+#include <AmiPeiLib.h>
+#include <Sha.h>
+#include <TcgMisc.h>
+#include <token.h>
+#include <TpmLib.h>
+#include <TcgPc.h>
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+#include "PPI\CpuIo.h"
+#include "PPI\LoadFile.h"
+#include <FFS.h>
+
+
+//*********************************************************************
+// GLOBAL DEFINITIONS
+//*********************************************************************
+
+
+#pragma pack(1)
+typedef struct _TCG_PEI_CALLBACK_CONTEXT
+{
+ PEI_TPM_PPI *TpmDevice;
+ EFI_PEI_SERVICES **PeiServices;
+} TCG_PEI_CALLBACK_CONTEXT;
+#pragma pack()
+
+
+EFI_GUID gEfiPeiAmiTcgLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+EFI_GUID gPeiTpmPpiGuid = PEI_TPM_PPI_GUID;
+EFI_GUID gPeiTcgPpiGuid = PEI_TCG_PPI_GUID;
+
+static
+EFI_STATUS
+__stdcall FillCallbackContext(
+ IN EFI_PEI_SERVICES **PeiService,
+ OUT TCG_PEI_CALLBACK_CONTEXT *CallbackContext )
+{
+ CallbackContext->PeiServices = PeiService;
+ return (*PeiService)->LocatePpi(
+ PeiService,
+ &gPeiTpmPpiGuid,
+ 0,
+ NULL,
+ &CallbackContext->TpmDevice
+ );
+}
+
+EFI_STATUS
+EFIAPI TcgPeiGetEventLog(
+ IN EFI_PEI_SERVICES **PeiServices,
+ OUT TCG_LOG_HOB **EventLog )
+{
+ EFI_STATUS Status;
+ VOID *HobStart;
+
+ Status = (*PeiServices)->GetHobList( PeiServices, &HobStart );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ return GetNextGuidHob( &HobStart, &gEfiPeiAmiTcgLogHobGuid, EventLog, NULL );
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Name: TcgPeiLogEvent
+//
+// Description: TCGPEI common function to Hash, Log and Extend data
+// using software SHA-1
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *Event,
+// IN *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiLogEvent(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCG_PCR_EVENT *Event,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ TCG_LOG_HOB *TcgLog;
+ TCG_PEI_CALLBACK_CONTEXT Context;
+ UINT8 HashAlgo = 0;
+
+
+ //only log events if TPM is not deactivated
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(Event->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = TcgPeiGetEventLog( PeiServices, &TcgLog );
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgCommonLogEvent(
+ &Context,
+ (TCG_PCR_EVENT*)(TcgLog + 1),
+ &TcgLog->TableSize,
+ TcgLog->TableMaxSize,
+ Event, HashAlgo);
+
+ if ( EFI_ERROR( Status )){
+ goto Exit;
+ }
+
+ *EventNum = TcgLog->EventNum;
+ TcgLog->EventNum++;
+
+Exit:
+ return Status;
+}
+
+
+
+
+
+EFI_STATUS
+__stdcall TcgPeiCommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PCRIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue )
+{
+ TPM_1_2_CMD_HEADER cmdHeader;
+ TPM_1_2_RET_HEADER retHeader;
+ TPM_TRANSMIT_BUFFER InBuffer[3], OutBuffer[2];
+ static BOOLEAN SupportType = 0xff;
+
+ InBuffer[0].Buffer = &cmdHeader;
+ InBuffer[0].Size = sizeof (cmdHeader);
+ InBuffer[1].Buffer = &PCRIndex;
+ InBuffer[1].Size = sizeof (PCRIndex);
+ InBuffer[2].Buffer = Digest->digest;
+ InBuffer[2].Size = sizeof (Digest->digest);
+
+ OutBuffer[0].Buffer = &retHeader;
+ OutBuffer[0].Size = sizeof (retHeader);
+ OutBuffer[1].Buffer = NewPCRValue->digest;
+ OutBuffer[1].Size = sizeof (NewPCRValue->digest);
+
+ cmdHeader.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdHeader.ParamSize = TPM_H2NL(sizeof (cmdHeader)
+ + sizeof (PCRIndex) + sizeof (Digest->digest));
+
+ cmdHeader.Ordinal = TPM_H2NL( TPM_ORD_Extend );
+ PCRIndex = TcgCommonH2NL( PCRIndex );
+
+ return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer );
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgPeiHashLogExtendEventSW
+// Description: TCGPEI Software function to Hash, Log and Extend data
+// using software SHA-1
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *HashData
+// IN HashDataLen
+// IN OUT *NewEvent,
+// OUT *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS TcgPeiHashLogExtendEventSW(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN OUT TCG_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status;
+ TCG_DIGEST NewPCRValue;
+ TCG_PEI_CALLBACK_CONTEXT Context;
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(NewEvent->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ Status = SHA1HashAll( &Context, HashData, HashDataLen, &NewEvent->Digest );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ Status = Context.TpmDevice->Init( Context.TpmDevice, PeiServices );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgPeiCommonExtend(
+ &Context,
+ NewEvent->PCRIndex,
+ &NewEvent->Digest,
+ &NewPCRValue
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgPeiLogEvent( This, PeiServices, NewEvent, EventNum );
+
+Exit:
+ Context.TpmDevice->Close( Context.TpmDevice, PeiServices );
+ return Status;
+}
+
+
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgPeiPassThroughToTpm
+//
+// Description: TCGPEI common function to abstract passing commands to the TPM
+// FIFO
+//
+// Input: IN *This
+// IN **PeiServices
+// IN TpmInputParameterBlockSize
+// IN *TpmInputParameterBlock
+// IN TpmOutputParameterBlockSize
+// IN *TpmOutputParameterBlock
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiPassThroughToTpm(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT32 TpmInputParameterBlockSize,
+ IN UINT8 *TpmInputParameterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock )
+{
+ EFI_STATUS Status;
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+ TCG_PEI_CALLBACK_CONTEXT Context;
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ InBuffer[0].Buffer = TpmInputParameterBlock;
+ InBuffer[0].Size = TpmInputParameterBlockSize;
+ OutBuffer[0].Buffer = TpmOutputParameterBlock;
+ OutBuffer[0].Size = TpmOutputParameterBlockSize;
+
+ return TcgCommonPassThrough(
+ &Context,
+ sizeof (InBuffer) / sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer
+ );
+}
+
+
+static PEI_TCG_PPI mTcgPpi = {
+ TcgPeiHashLogExtendEventSW,
+ TcgPeiLogEvent,
+ TcgPeiPassThroughToTpm
+};
+
+static EFI_PEI_PPI_DESCRIPTOR mTcgPpiList[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTcgPpiGuid,
+ &mTcgPpi
+ }
+};
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgPeiEntry
+//
+// Description: Entry point to Memory Absent and Memory Present Initialization
+// for TPM
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiMemoryCallbackEntry(
+ IN EFI_PEI_SERVICES **PeiServices
+)
+{
+ EFI_PEI_PPI_DESCRIPTOR *PpiDesc;
+ PEI_TCG_PPI *TcgPpi;
+ EFI_STATUS Status;
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gPeiTcgPpiGuid,
+ 0,
+ &PpiDesc,
+ &TcgPpi);
+
+
+ Status = (*PeiServices)->ReInstallPpi(
+ PeiServices,
+ PpiDesc,
+ &mTcgPpiList[0] );
+
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gPeiTcgPpiGuid,
+ 0,
+ &PpiDesc,
+ &TcgPpi );
+
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ return Status;
+}
+
+
diff --git a/Core/EM/TCG2/Common/TcgPeiAfterMem.cif b/Core/EM/TCG2/Common/TcgPeiAfterMem.cif
new file mode 100644
index 0000000..bb6807e
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPeiAfterMem.cif
@@ -0,0 +1,11 @@
+<component>
+ name = "TcgPeiAfterMem"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common"
+ RefName = "TcgPeiAfterMem"
+[files]
+"TcgPeiAfterMem.c"
+"xTcgPeiAfterMem.c"
+"TcgPeiAfterMem.mak"
+"TcgTcmPeiAfterMem.c"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/TcgPeiAfterMem.mak b/Core/EM/TCG2/Common/TcgPeiAfterMem.mak
new file mode 100644
index 0000000..b48fb94
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPeiAfterMem.mak
@@ -0,0 +1,149 @@
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#*************************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPeiAfterMem/TcgPeiAfterMem.mak 1 4/21/14 2:16p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:16p $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPeiAfterMem/TcgPeiAfterMem.mak $
+#
+# 1 4/21/14 2:16p Fredericko
+#
+# 1 10/08/13 12:03p Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 2 10/03/13 1:57p Fredericko
+#
+# 1 7/10/13 5:51p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+#
+# 3 12/12/11 3:32p Fredericko
+# [TAG] EIP76865
+# [Category] Improvement
+# [Description] Dual Support for TCM and TPM. System could hang in TXT
+# if txt is enabled in setup
+# [Files] AmiTcgPlatfompeilib.c, AmiTcgPlatformPpi.cif,
+# AmiTcgPlatformPpi.h, AmiTcgPlatformProtocol.cif,
+# AmiTcgPlatformProtocol.h,
+# EMpTcmPei.c, TcgDxe.cif, TcgPei.cif, TcgPeiAfterMem.cif,
+# TcgPeiAfterMem.mak, TcgTcmPeiAfterMem.c, xTcgDxe.c, xTcgPei.c,
+# xTcgPeiAfterMem.c
+#
+# 2 9/27/11 10:23p Fredericko
+# [TAG] EIP67286
+# [Category] Improvement
+# [Description] changes for Tcg Setup policy
+# [Files] Tcg.sdl
+# TcgPei.cif
+# TcgPei.mak
+# xtcgPei.c
+# xTcgPeiAfterMem.c
+# TcgPeiAfterMem.mak
+# TcgDxe.cif
+# TcgDxe.mak
+# xTcgDxe.c
+# AmiTcgPlatformPeilib.c
+# AmiTcgPlatformDxelib.c
+#
+# 1 8/22/11 1:45p Fredericko
+# [TAG] EIP61168
+# [Category] Improvement
+# [Description] Reload TCG PPI from memory when Memory is Installed
+# [Files] TcgPeiAfterMem.cif
+# TcgPeiAfterMem.c
+# xTcgPeiAfterMem.c
+# TcgPeiAfterMem.mak
+#
+# 25 4/22/11 8:49p Fredericko
+# Changes for building in x32 bit mode.
+#
+# 24 3/29/11 12:56p Fredericko
+#
+# [TAG] EIP 54642
+# [Category] Improvement
+# [Description] 1. Checkin Files related to TCG function override
+# 2. Include TCM and TPM auto detection
+# [Files] Affects all TCG files
+#
+#
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: TCGPEI.MAK
+#
+# Description: Make file for the TcgPei component
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+all : tcgPeiAftermem
+
+tcgPeiAftermem : $(BUILD_DIR)\TcgPeiAftermem.mak TcgPeiBinMem
+
+$(BUILD_DIR)\TcgPeiAftermem.mak : $(TCGPEI_DIR)\$(@B).cif $(TCGPEI_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(TCGPEI_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+TCGPEIMEM_CFLAGS=$(CFLAGS)\
+ /I$(TcgPlatformSetupPeiPolicy_DIR)\
+ /I$(TCG_DIR)\
+ /I$(TPM12_DIR)\
+ /I$(TCG_DIR)\Common\
+ /I$(TCG_BOARD_OEM__DIR)\
+
+TCG_CORE_POSTMEM_OBJECTS = \
+$(BUILD_DIR)\$(TCGPEI_DIR)\TcgPeiAfterMem.obj \
+$(BUILD_DIR)\$(TCGPEI_DIR)\TcgTcmPeiAfterMem.obj \
+$(BUILD_DIR)\$(TCGPEI_DIR)\xTcgPeiAfterMem.obj
+
+!IFNDEF LIB_BUILD_DIR
+!IF "$(PROCESSOR)"=="x64"
+TCGLIB=$(BUILD_DIR)\IA32\TisLib.lib.
+AMITCMLIB = $(BUILD_DIR)\IA32\AmiTcmlib.lib
+Tpm20Crb_lib = $(BUILD_DIR)\IA32\Tpm20CRBLib.lib
+!ELSE
+TCGLIB=$(BUILD_DIR)\TisLib.lib
+AMITCMLIB = $(BUILD_DIR)\AmiTcmlib.lib
+!ENDIF
+!ENDIF #LIB_BUILD_DIR
+
+
+TcgPeiBinMem : $(AMIPEILIB) $(BUILD_DIR)\AmiTcgLibPei.lib
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TcgPeiAftermem.mak all\
+ "CFLAGS=$(TCGPEIMEM_CFLAGS) "\
+ GUID=12345678-930A-4a95-AB04-2E6CFDFF6631\
+ "OBJECTS=$(TCG_CORE_POSTMEM_OBJECTS)" \
+ ENTRY_POINT=ReInstallTcgServiceAfterMem \
+ TYPE=PEIM \
+ DEPEX1=$(TCGPEI_DIR)\TcgPei.dxs \
+ DEPEX1_TYPE=EFI_SECTION_PEI_DEPEX \
+ EXT_HEADERS=$(BUILD_DIR)\token.h \
+ COMPRESS=1\
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
diff --git a/Core/EM/TCG2/Common/TcgPrivate.c b/Core/EM/TCG2/Common/TcgPrivate.c
new file mode 100644
index 0000000..2ee8179
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPrivate.c
@@ -0,0 +1,70 @@
+/*++
+
+ Copyright (c) 1999 - 2007 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TcgPrivate.c
+
+ Abstract:
+
+ TCG private interface GUID used internally by TCG modules
+
+ --*/
+/*++
+ This file contains an 'Intel Peripheral Driver' and uniquely
+ identified as "Intel Mobile Silicon Support Module" and is
+ licensed for Intel Mobile CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgPrivate.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgPrivate.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 12:00p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 5/19/10 5:20p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgPrivate.c
+//
+// Description:
+// Contains guid definition for Tcg Private protocol
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <EFI.h>
+#include "TcgPrivate.h"
+
+EFI_GUID gEfiTcgPrivateInterfaceGuid = EFI_TCG_PRIVATE_INTERFACE_GUID;
diff --git a/Core/EM/TCG2/Common/TcgPrivate.h b/Core/EM/TCG2/Common/TcgPrivate.h
new file mode 100644
index 0000000..2b55058
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgPrivate.h
@@ -0,0 +1,400 @@
+/*++
+
+ Copyright (c) 1999 - 2007 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TcgPrivate.h
+
+ Abstract:
+
+ Private interface used internally by TCG modules
+
+ --*/
+/*++
+ This file contains an 'Intel Peripheral Driver' and uniquely
+ identified as "Intel Mobile Silicon Support Module" and is
+ licensed for Intel Mobile CPUs and chipsets under the terms of your
+ license agreement with Intel or your vendor. This file may
+ be modified by the user, subject to additional terms of the
+ license agreement
+ --*/
+
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgPrivate.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/TcgPrivate.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:59a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:58p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 8 3/29/11 12:25p Fredericko
+//
+// 7 3/28/11 12:23p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 6 7/09/10 3:32p Fredericko
+// Updated TCG structures for image measurement.
+//
+// 5 5/19/10 5:20p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgPrivate.h
+//
+// Description:
+// Header file for Tcg private protocol definitions
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCG_PRIVATE_H_
+#define _TCG_PRIVATE_H_
+
+#define EFI_TCG_PRIVATE_INTERFACE_GUID \
+ { 0x8c4c9a41, 0xbf56, 0x4627, 0x9e, 0xa, 0xc8, 0x38, 0x6d, 0x66, 0x11, 0x5c }
+
+
+#define TCG_EFI_IMAGE_DOS_SIGNATURE 0x5A4D // MZ
+#define TCG_EFI_TE_IMAGE_HEADER_SIGNATURE 0x5A56 // TE
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_TLS 9
+#define TCG_EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
+#define TCG_MBR_TYPE_EFI_PARTITION_TABLE_HEADER 0x02
+#define TCG_EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16
+#define END_DEVICE_PATH_TYPE 0x7F
+#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xFF
+#define EFI_DP_TYPE_MASK 0x7F
+#define EFI_DP_TYPE_UNPACKED 0x80
+#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01
+// Type definitions for the Hard drive device path
+#define TCG_MBR_TYPE_MASTER_BOOT_RECORD 0x01
+#define TCG_MBR_TYPE_EFI_PARTITION_TABLE_HEADER 0x02
+
+// Needed Partition Type definitions for MBR
+#define TCG_NO_PARTITION 0x0
+#define TCG_EXTENDED_PARTITION 0x05
+#define TCG_WIN95_EXTENDED_PARTITION 0x0f
+
+
+
+
+#define DP_IS_END_TYPE(a)
+#define DP_IS_END_SUBTYPE(a) ( ((a)->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE )
+
+#define DevicePathType(a) ( ((a)->Type) & EFI_DP_TYPE_MASK )
+#define DevicePathSubType(a) ( (a)->SubType )
+#define DevicePathNodeLength(a) ( ((a)->Length[0]) | ((a)->Length[1] << 8) )
+
+#define IsDevicePathEndType(a) ( DevicePathType(a) == END_DEVICE_PATH_TYPE )
+#define IsDevicePathEndSubType(a) ( (a)->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE )
+#define IsDevicePathEnd(a) ( IsDevicePathEndType(a) && IsDevicePathEndSubType(a) )
+#define NextDevicePathNode(a) ( (EFI_DEVICE_PATH_PROTOCOL *) ( ((UINT8 *) (a)) + DevicePathNodeLength(a)))
+
+#define IsDevicePathEnd(a) ( IsDevicePathEndType(a) && IsDevicePathEndSubType(a) )
+
+typedef struct {
+ UINT32 VirtualAddress;
+ UINT32 Size;
+} TCG_EFI_IMAGE_DATA_DIRECTORY;
+
+typedef struct {
+ UINT16 Machine;
+ UINT16 NumberOfSections;
+ UINT32 TimeDateStamp;
+ UINT32 PointerToSymbolTable;
+ UINT32 NumberOfSymbols;
+ UINT16 SizeOfOptionalHeader;
+ UINT16 Characteristics;
+} TCG_EFI_IMAGE_FILE_HEADER;
+
+
+#if EFIx64
+typedef struct {
+ //
+ // Standard fields.
+ //
+ UINT16 Magic;
+ UINT8 MajorLinkerVersion;
+ UINT8 MinorLinkerVersion;
+ UINT32 SizeOfCode;
+ UINT32 SizeOfInitializedData;
+ UINT32 SizeOfUninitializedData;
+ UINT32 AddressOfEntryPoint;
+ UINT32 BaseOfCode;
+ //
+ // NT additional fields.
+ //
+ UINT64 ImageBase;
+ UINT32 SectionAlignment;
+ UINT32 FileAlignment;
+ UINT16 MajorOperatingSystemVersion;
+ UINT16 MinorOperatingSystemVersion;
+ UINT16 MajorImageVersion;
+ UINT16 MinorImageVersion;
+ UINT16 MajorSubsystemVersion;
+ UINT16 MinorSubsystemVersion;
+ UINT32 Win32VersionValue;
+ UINT32 SizeOfImage;
+ UINT32 SizeOfHeaders;
+ UINT32 CheckSum;
+ UINT16 Subsystem;
+ UINT16 DllCharacteristics;
+ UINT64 SizeOfStackReserve;
+ UINT64 SizeOfStackCommit;
+ UINT64 SizeOfHeapReserve;
+ UINT64 SizeOfHeapCommit;
+ UINT32 LoaderFlags;
+ UINT32 NumberOfRvaAndSizes;
+ TCG_EFI_IMAGE_DATA_DIRECTORY DataDirectory[TCG_EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
+} TCG_EFI_IMAGE_OPTIONAL_HEADER64;
+
+typedef struct {
+ UINT32 Signature;
+ TCG_EFI_IMAGE_FILE_HEADER FileHeader;
+ TCG_EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader;
+} TCG_EFI_IMAGE_NT_HEADERS64;
+
+
+typedef TCG_EFI_IMAGE_OPTIONAL_HEADER64 TCG_EFI_IMAGE_OPTIONAL_HEADER;
+typedef TCG_EFI_IMAGE_NT_HEADERS64 TCG_EFI_IMAGE_NT_HEADERS;
+
+#else
+
+typedef struct {
+ //
+ // Standard fields.
+ //
+ UINT16 Magic;
+ UINT8 MajorLinkerVersion;
+ UINT8 MinorLinkerVersion;
+ UINT32 SizeOfCode;
+ UINT32 SizeOfInitializedData;
+ UINT32 SizeOfUninitializedData;
+ UINT32 AddressOfEntryPoint;
+ UINT32 BaseOfCode;
+ UINT32 BaseOfData;
+ //
+ // NT additional fields.
+ //
+ UINT32 ImageBase;
+ UINT32 SectionAlignment;
+ UINT32 FileAlignment;
+ UINT16 MajorOperatingSystemVersion;
+ UINT16 MinorOperatingSystemVersion;
+ UINT16 MajorImageVersion;
+ UINT16 MinorImageVersion;
+ UINT16 MajorSubsystemVersion;
+ UINT16 MinorSubsystemVersion;
+ UINT32 Win32VersionValue;
+ UINT32 SizeOfImage;
+ UINT32 SizeOfHeaders;
+ UINT32 CheckSum;
+ UINT16 Subsystem;
+ UINT16 DllCharacteristics;
+ UINT32 SizeOfStackReserve;
+ UINT32 SizeOfStackCommit;
+ UINT32 SizeOfHeapReserve;
+ UINT32 SizeOfHeapCommit;
+ UINT32 LoaderFlags;
+ UINT32 NumberOfRvaAndSizes;
+ TCG_EFI_IMAGE_DATA_DIRECTORY DataDirectory[TCG_EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
+} TCG_EFI_IMAGE_OPTIONAL_HEADER32;
+
+typedef struct {
+ UINT32 Signature;
+ TCG_EFI_IMAGE_FILE_HEADER FileHeader;
+ TCG_EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader;
+} TCG_EFI_IMAGE_NT_HEADERS32;
+
+
+typedef TCG_EFI_IMAGE_OPTIONAL_HEADER32 TCG_EFI_IMAGE_OPTIONAL_HEADER;
+typedef TCG_EFI_IMAGE_NT_HEADERS32 TCG_EFI_IMAGE_NT_HEADERS;
+#endif
+
+#define TCG_EFI_IMAGE_SIZEOF_SHORT_NAME 8
+
+typedef struct {
+ UINT8 Name[TCG_EFI_IMAGE_SIZEOF_SHORT_NAME];
+ union {
+ UINT32 PhysicalAddress;
+ UINT32 VirtualSize;
+ } Misc;
+ UINT32 VirtualAddress;
+ UINT32 SizeOfRawData;
+ UINT32 PointerToRawData;
+ UINT32 PointerToRelocations;
+ UINT32 PointerToLinenumbers;
+ UINT16 NumberOfRelocations;
+ UINT16 NumberOfLinenumbers;
+ UINT32 Characteristics;
+} TCG_EFI_IMAGE_SECTION_HEADER;
+
+typedef struct {
+ UINT16 Signature; // signature for TE format = "VZ"
+ UINT16 Machine; // from the original file header
+ UINT8 NumberOfSections; // from the original file header
+ UINT8 Subsystem; // from original optional header
+ UINT16 StrippedSize; // how many bytes we removed from the header
+ UINT32 AddressOfEntryPoint; // offset to entry point -- from original optional header
+ UINT32 BaseOfCode; // from original image -- required for ITP debug
+ UINT64 ImageBase; // from original file header
+ TCG_EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; // only base relocation and debug directory
+} TCG_EFI_TE_IMAGE_HEADER;
+
+typedef struct {
+ UINT16 e_magic; // Magic number
+ UINT16 e_cblp; // Bytes on last page of file
+ UINT16 e_cp; // Pages in file
+ UINT16 e_crlc; // Relocations
+ UINT16 e_cparhdr; // Size of header in paragraphs
+ UINT16 e_minalloc; // Minimum extra paragraphs needed
+ UINT16 e_maxalloc; // Maximum extra paragraphs needed
+ UINT16 e_ss; // Initial (relative) SS value
+ UINT16 e_sp; // Initial SP value
+ UINT16 e_csum; // Checksum
+ UINT16 e_ip; // Initial IP value
+ UINT16 e_cs; // Initial (relative) CS value
+ UINT16 e_lfarlc; // File address of relocation table
+ UINT16 e_ovno; // Overlay number
+ UINT16 e_res[4]; // Reserved words
+ UINT16 e_oemid; // OEM identifier (for e_oeminfo)
+ UINT16 e_oeminfo; // OEM information; e_oemid specific
+ UINT16 e_res2[10]; // Reserved words
+ UINT32 e_lfanew; // File address of new exe header
+} TCG_EFI_IMAGE_DOS_HEADER;
+
+
+// GPT Partition Entry
+//<AMI_STHDR_START>
+//============================================================================
+// Structure: PARTITION_ENTRY
+//
+// Description: Data Structure definition of a partion entry in the GPT table
+//
+// Fields:
+// PartitionTypeGuid - EFI_GUID - contains GUID that defines that type
+// of GUID
+// UniquePartitionGuid - EFI_GUID - contains unique GUID for each
+// partition
+// StartingLba - EFI_LBA - first LBA of the partition
+// EndingLba - EFI_LBA - last logical block address
+// Attributes - UINT64 - UEFI defined attributes
+// Bit 0 - Partition is required for platform to function
+// Bits 1 - 47 - undefined
+// Bits 48 - 64 - reserved for GUID specific use
+// PartitionName[36] - CHAR16 - unicode string containing the name of
+// the partition
+//
+// Referral:
+// EFI_LBA
+//============================================================================
+//<AMI_STHDR_END>
+typedef struct
+{
+ EFI_GUID PartitionTypeGuid;
+ EFI_GUID UniquePartitionGuid;
+ EFI_LBA StartingLba;
+ EFI_LBA EndingLba;
+ UINT64 Attributes;
+ CHAR16 PartitionName[36];
+} TCG_EFI_PARTITION_ENTRY;
+
+
+typedef struct
+{
+ EFI_TABLE_HEADER Header;
+ EFI_LBA MyLba;
+ EFI_LBA AlternateLba;
+ EFI_LBA FirstUsableLba;
+ EFI_LBA LastUsableLba;
+ EFI_GUID DiskGuid;
+ EFI_LBA PartitionEntryLba;
+ UINT32 NumberOfPartitionEntries;
+ UINT32 SizeOfPartitionEntry;
+ UINT32 Crc32;
+} TCG_EFI_PARTITION_TABLE_HEADER;
+
+
+typedef struct {
+ TCG_EFI_PARTITION_TABLE_HEADER EfiPartitionHeader;
+ UINTN NumberOfPartitions;
+ TCG_EFI_PARTITION_ENTRY Partitions[1];
+} TCG_EFI_GPT_DATA;
+
+
+//
+// EFI TCG Platform Protocol
+//
+typedef
+EFI_STATUS
+(EFIAPI *EFI_TCG_MEASURE_PE_IMAGE) (
+ IN BOOLEAN BootPolicy,
+ IN EFI_PHYSICAL_ADDRESS ImageAddress,
+ IN UINTN ImageSize,
+ IN UINTN LinkTimeBase,
+ IN UINT16 ImageType,
+ IN EFI_HANDLE DeviceHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath
+ );
+
+
+typedef
+EFI_STATUS
+(EFIAPI *EFI_TCG_MEASURE_ACTION) (
+ IN CHAR8 *ActionString
+ );
+
+
+typedef
+EFI_STATUS
+(EFIAPI *EFI_TCG_MEASURE_GPT_TABLE) (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ );
+
+
+typedef struct _EFI_TCG_PLATFORM_PROTOCOL {
+ EFI_TCG_MEASURE_PE_IMAGE MeasurePeImage;
+ EFI_TCG_MEASURE_ACTION MeasureAction;
+ EFI_TCG_MEASURE_GPT_TABLE MeasureGptTable;
+} EFI_TCG_PLATFORM_PROTOCOL;
+
+extern EFI_GUID gEfiTcgPrivateInterfaceGuid;
+#endif // _TCG_PRIVATE_H_
diff --git a/Core/EM/TCG2/Common/TcgTcmPei.c b/Core/EM/TCG2/Common/TcgTcmPei.c
new file mode 100644
index 0000000..ec48285
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgTcmPei.c
@@ -0,0 +1,476 @@
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgTcmPei.c 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgTcmPei.c $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 1:54p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 4 4/27/12 6:04p Fredericko
+// remove unused functions
+//
+// 3 4/01/11 9:33a Fredericko
+// Updated function Header
+//
+// 2 3/29/11 12:58p Fredericko
+//
+// 1 3/28/11 2:14p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 51 11/30/10 11:31p Fredericko
+// [TAG} EIP45885
+// [Category] NEW FEATURE
+// [Description] Provide hook to override Ppi request confirmation
+// [Files] TCGMisc.h, xTcgDxe.c, TcgPei.c
+//
+// 50 8/04/10 5:16p Fredericko
+// Changes to flow of Lock Physical Presence for support Smi PPI changes
+//
+// 49 5/21/10 4:31p Fredericko
+// Changes for some build errors that happened with MOR support
+//
+// 48 5/19/10 5:51p Fredericko
+// Updated AMI Function Headers
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgPei.c
+//
+// Description:
+// Functions for early initialization of TPM are executed here
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include "TcgCommon.h"
+#include <AmiPeiLib.h>
+#include <Sha.h>
+#include <TcgMisc.h>
+#include <token.h>
+#include <TcgPc.h>
+#include "PPI\TcgService\TcgTcmService.h"
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+#include "PPI\CpuIo.h"
+#include "PPI\LoadFile.h"
+#include <FFS.h>
+
+
+//*********************************************************************
+// GLOBAL DEFINITIONS
+//*********************************************************************
+
+EFI_GUID gPeiTcmPpiGuid = PEI_TPM_PPI_GUID;
+EFI_GUID gPeiTcgTcmPpiGuid = PEI_TCG_PPI_GUID;
+
+#pragma pack(1)
+typedef struct _TCG_PEI_CALLBACK_CONTEXT
+{
+ PEI_TPM_PPI *TpmDevice;
+ EFI_PEI_SERVICES **PeiServices;
+} TCG_PEI_CALLBACK_CONTEXT;
+#pragma pack()
+
+EFI_GUID gEfiPeiAmiTcmTcgLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+
+EFI_STATUS
+EFIAPI TcmPeiLogEvent(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCM_PCR_EVENT *Event,
+ OUT UINT32 *EventNum );
+
+EFI_STATUS
+EFIAPI TcgPeiHashLogExtendEventTcm(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN OUT TCM_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum );
+
+
+static
+EFI_STATUS
+__stdcall FillCallbackContext(
+ IN EFI_PEI_SERVICES **PeiService,
+ OUT TCG_PEI_CALLBACK_CONTEXT *CallbackContext )
+{
+ CallbackContext->PeiServices = PeiService;
+ return (*PeiService)->LocatePpi(
+ PeiService,
+ &gPeiTcmPpiGuid,
+ 0,
+ NULL,
+ &CallbackContext->TpmDevice
+ );
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmPeiGetEventLog
+//
+// Description: Helper function for logging TCM events
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+// OUT TCG_LOG_HOB **EventLog
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcmPeiGetEventLog(
+ IN EFI_PEI_SERVICES **PeiServices,
+ OUT TCG_LOG_HOB **EventLog )
+{
+ EFI_STATUS Status;
+ VOID *HobStart;
+ EFI_GUID gEfiPeiAmiTcgLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+
+ Status = (*PeiServices)->GetHobList( PeiServices, &HobStart );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ return GetNextGuidHob( &HobStart, &gEfiPeiAmiTcgLogHobGuid, EventLog, NULL );
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgPeiPassThroughToTpm
+//
+// Description: TCGPEI common function to abstract passing commands to the TPM
+// FIFO
+//
+// Input: IN *This
+// IN **PeiServices
+// IN TpmInputParameterBlockSize
+// IN *TpmInputParameterBlock
+// IN TpmOutputParameterBlockSize
+// IN *TpmOutputParameterBlock
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiPassThroughToTpm(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT32 TpmInputParameterBlockSize,
+ IN UINT8 *TpmInputParameterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock );
+
+
+
+static PEI_TCM_PPI mTcmPpi = {
+ TcgPeiHashLogExtendEventTcm,
+ TcmPeiLogEvent,
+ TcgPeiPassThroughToTpm
+};
+
+
+static EFI_PEI_PPI_DESCRIPTOR mTcgPpiList[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTcgTcmPpiGuid,
+ &mTcmPpi
+ }
+};
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: IntTcmTcgPeiGetCapabilities
+//
+// Description: Executes TCM operation to read capabilities
+//
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: TCM_Capabilities_PermanentFlag
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+TCM_Capabilities_PermanentFlag IntTcmTcgPeiGetCapabilities(
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ TCM_Capabilities_PermanentFlag * cap = NULL;
+ EFI_STATUS Status;
+ TPM_GetCapabilities_Input cmdGetCap;
+ UINT8 result[0x100];
+
+ TCG_PEI_CALLBACK_CONTEXT Context;
+
+ cmdGetCap.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdGetCap.ParamSize = TPM_H2NL( sizeof (cmdGetCap));
+ cmdGetCap.CommandCode = TPM_H2NL( TCM_ORD_GetCapability );
+ cmdGetCap.caparea = TPM_H2NL( TPM_CAP_FLAG );
+ cmdGetCap.subCapSize = TPM_H2NL( 4 ); // subCap is always 32bit long
+ cmdGetCap.subCap = TPM_H2NL( TPM_CAP_FLAG_PERMANENT );
+
+ Status = FillCallbackContext( PeiServices, &Context );
+
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = Context.TpmDevice->Init( Context.TpmDevice, PeiServices );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = TcgPeiPassThroughToTpm(
+ &mTcmPpi,
+ PeiServices,
+ sizeof(cmdGetCap),
+ (UINT8*)&cmdGetCap,
+ 0x100,
+ result );
+
+ cap = (TCM_Capabilities_PermanentFlag*)result;
+
+ PEI_TRACE((-1, PeiServices,
+ "GetCapability: %r; size: %x; retCode:%x; tag:%x; bytes %08x\n",
+ Status,TPM_H2NL( cap->ParamSize ), TPM_H2NL(cap->RetCode ),
+ (UINT32)TPM_H2NS(cap->tag ), TPM_H2NL( *(UINT32*)&cap->disabled )));
+
+ Status = Context.TpmDevice->Close( Context.TpmDevice, PeiServices );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ return *cap;
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Name: TcmPeiLogEvent
+//
+// Description: TCM common function to log PEI events
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *Event,
+// IN *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS
+EFIAPI TcmPeiLogEvent(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCM_PCR_EVENT *Event,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ TCG_LOG_HOB *TcgLog;
+ TCG_PEI_CALLBACK_CONTEXT Context;
+ TCM_Capabilities_PermanentFlag Cap;
+
+ //only log events if TPM is not deactivated
+ Cap = IntTcmTcgPeiGetCapabilities( PeiServices );
+
+ if ( !Cap.deactivated )
+ {
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = TcmPeiGetEventLog(PeiServices, &TcgLog );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcmCommonLogEvent(
+ &Context,
+ (TCM_PCR_EVENT*)(TcgLog + 1),
+ &TcgLog->TableSize,
+ TcgLog->TableMaxSize,
+ (TCM_PCR_EVENT *)Event
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ *EventNum = TcgLog->EventNum;
+ TcgLog->EventNum++;
+ }
+Exit:
+ return Status;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Name: TcgPeiHashLogExtendEventTcm
+//
+// Description: Tcm common function to Hash, Log and Extend data
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *HashData
+// IN HashDataLen
+// IN *NewEvent,
+// IN *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiHashLogExtendEventTcm(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN OUT TCM_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status;
+ UINT32 Sha1MaxBytes;
+ TCM_DIGEST NewPCRValue;
+ TCG_PEI_CALLBACK_CONTEXT Context;
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgCommonSha1Start( &Context, TCG_ALG_SHA, &Sha1MaxBytes );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgCommonSha1Update(
+ &Context,
+ HashData,
+ HashDataLen,
+ Sha1MaxBytes
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ HashData += (HashDataLen & ~63);
+ HashDataLen &= 63;
+
+ Status = TcmCommonSha1CompleteExtend(
+ &Context,
+ HashData,
+ HashDataLen,
+ NewEvent->PCRIndex,
+ &NewEvent->Digest,
+ &NewPCRValue
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcmPeiLogEvent( This, PeiServices, NewEvent, EventNum );
+
+Exit:
+ return Status;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgTcmPeiEntry
+//
+// Description: Entry point for TCM device initialization
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgTcmPeiEntry(
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ EFI_STATUS Status;
+
+ Status = (*PeiServices)->InstallPpi( PeiServices, mTcgPpiList );
+ return Status;
+}
diff --git a/Core/EM/TCG2/Common/TcgTcmPeiAfterMem.c b/Core/EM/TCG2/Common/TcgTcmPeiAfterMem.c
new file mode 100644
index 0000000..531da8f
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgTcmPeiAfterMem.c
@@ -0,0 +1,538 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TcgPei.c
+
+ Abstract:
+
+ PEIM that provides TCG services
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPeiAfterMem/TcgTcmPeiAfterMem.c 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPeiAfterMem/TcgTcmPeiAfterMem.c $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:03p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 1:57p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 2 1/12/12 12:12p Fredericko
+// Remove unused function declaration.
+//
+// 1 12/12/11 12:40p Fredericko
+// [TAG] EIP76865
+// [Category] Improvement
+// [Description] Dual Support for TCM and TPM. System could hang in TXT
+// if txt is enabled in setup
+// [Files] AmiTcgPlatfompeilib.c, AmiTcgPlatformPpi.cif,
+// AmiTcgPlatformPpi.h, AmiTcgPlatformProtocol.cif,
+// AmiTcgPlatformProtocol.h,
+// EMpTcmPei.c, TcgDxe.cif, TcgPei.cif, TcgPeiAfterMem.cif,
+// TcgPeiAfterMem.mak, TcgTcmPeiAfterMem.c, xTcgDxe.c, xTcgPei.c,
+// xTcgPeiAfterMem.c
+//
+//*************************************************************************
+#include <Efi.h>
+#include "TcgCommon.h"
+#include <AmiPeiLib.h>
+#include <Sha.h>
+#include <TcgMisc.h>
+#include <token.h>
+#include <TcgPc.h>
+#include "PPI\TcgService\TcgTcmService.h"
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+#include "PPI\CpuIo.h"
+#include "PPI\LoadFile.h"
+#include <FFS.h>
+
+
+//*********************************************************************
+// GLOBAL DEFINITIONS
+//*********************************************************************
+
+
+#pragma pack(1)
+typedef struct _TCG_PEI_CALLBACK_CONTEXT
+{
+ PEI_TPM_PPI *TpmDevice;
+ EFI_PEI_SERVICES **PeiServices;
+} TCG_PEI_CALLBACK_CONTEXT;
+#pragma pack()
+
+
+EFI_GUID gPeiTcmPpiGuid = PEI_TPM_PPI_GUID;
+EFI_GUID gPeiTcgTcmPpiGuid = PEI_TCG_PPI_GUID;
+
+static
+EFI_STATUS
+__stdcall FillCallbackContext(
+ IN EFI_PEI_SERVICES **PeiService,
+ OUT TCG_PEI_CALLBACK_CONTEXT *CallbackContext )
+{
+ CallbackContext->PeiServices = PeiService;
+ return (*PeiService)->LocatePpi(
+ PeiService,
+ &gPeiTpmPpiGuid,
+ 0,
+ NULL,
+ &CallbackContext->TpmDevice
+ );
+}
+
+EFI_STATUS
+EFIAPI TcmPeiLogEvent(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCM_PCR_EVENT *Event,
+ OUT UINT32 *EventNum );
+
+EFI_STATUS
+EFIAPI TcgPeiHashLogExtendEventTcm(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN OUT TCM_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum );
+
+
+EFI_STATUS
+EFIAPI TcgPeiPassThroughToTcm(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT32 TpmInputParameterBlockSize,
+ IN UINT8 *TpmInputParameterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock );
+
+
+
+static PEI_TCM_PPI mTcmPpi = {
+ TcgPeiHashLogExtendEventTcm,
+ TcmPeiLogEvent,
+ TcgPeiPassThroughToTcm
+};
+
+
+static EFI_PEI_PPI_DESCRIPTOR mTcgTcgPpiList[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTcgTcmPpiGuid,
+ &mTcmPpi
+ }
+};
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcmPeiGetEventLog
+//
+// Description: Helper function for logging TCM events
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+// OUT TCG_LOG_HOB **EventLog
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcmPeiGetEventLog(
+ IN EFI_PEI_SERVICES **PeiServices,
+ OUT TCG_LOG_HOB **EventLog )
+{
+ EFI_STATUS Status;
+ VOID *HobStart;
+ EFI_GUID gEfiPeiAmiTcgTcmLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+
+ Status = (*PeiServices)->GetHobList( PeiServices, &HobStart );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ return GetNextGuidHob( &HobStart, &gEfiPeiAmiTcgTcmLogHobGuid, EventLog, NULL );
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: IntTcmTcgPeiGetCapabilities
+//
+// Description: Executes TCM operation to read capabilities
+//
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: TCM_Capabilities_PermanentFlag
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+TCM_Capabilities_PermanentFlag IntTcmTcgPeiGetCapabilities(
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ TCM_Capabilities_PermanentFlag * cap = NULL;
+ EFI_STATUS Status;
+ TPM_GetCapabilities_Input cmdGetCap;
+ UINT8 result[0x100];
+
+ TCG_PEI_CALLBACK_CONTEXT Context;
+
+ cmdGetCap.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdGetCap.ParamSize = TPM_H2NL( sizeof (cmdGetCap));
+ cmdGetCap.CommandCode = TPM_H2NL( TCM_ORD_GetCapability );
+ cmdGetCap.caparea = TPM_H2NL( TPM_CAP_FLAG );
+ cmdGetCap.subCapSize = TPM_H2NL( 4 ); // subCap is always 32bit long
+ cmdGetCap.subCap = TPM_H2NL( TPM_CAP_FLAG_PERMANENT );
+
+ Status = FillCallbackContext( PeiServices, &Context );
+
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = Context.TpmDevice->Init( Context.TpmDevice, PeiServices );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = TcgPeiPassThroughToTcm(
+ &mTcmPpi,
+ PeiServices,
+ sizeof(cmdGetCap),
+ (UINT8*)&cmdGetCap,
+ 0x100,
+ result );
+
+ cap = (TCM_Capabilities_PermanentFlag*)result;
+
+ PEI_TRACE((-1, PeiServices,
+ "GetCapability: %r; size: %x; retCode:%x; tag:%x; bytes %08x\n",
+ Status,TPM_H2NL( cap->ParamSize ), TPM_H2NL(cap->RetCode ),
+ (UINT32)TPM_H2NS(cap->tag ), TPM_H2NL( *(UINT32*)&cap->disabled )));
+
+ Status = Context.TpmDevice->Close( Context.TpmDevice, PeiServices );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ return *cap;
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Name: TcmPeiLogEvent
+//
+// Description: TCM common function to log PEI events
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *Event,
+// IN *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS
+EFIAPI TcmPeiLogEvent(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCM_PCR_EVENT *Event,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ TCG_LOG_HOB *TcgLog;
+ TCG_PEI_CALLBACK_CONTEXT Context;
+ TCM_Capabilities_PermanentFlag Cap;
+
+ //only log events if TPM is not deactivated
+ Cap = IntTcmTcgPeiGetCapabilities( PeiServices );
+
+ if ( !Cap.deactivated )
+ {
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = TcmPeiGetEventLog(PeiServices, &TcgLog );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcmCommonLogEvent(
+ &Context,
+ (TCM_PCR_EVENT*)(TcgLog + 1),
+ &TcgLog->TableSize,
+ TcgLog->TableMaxSize,
+ (TCM_PCR_EVENT *)Event
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ *EventNum = TcgLog->EventNum;
+ TcgLog->EventNum++;
+ }
+Exit:
+ return Status;
+}
+
+
+
+
+
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Name: TcgPeiHashLogExtendEventTcm
+//
+// Description: Tcm common function to Hash, Log and Extend data
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *HashData
+// IN HashDataLen
+// IN *NewEvent,
+// IN *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiHashLogExtendEventTcm(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN OUT TCM_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status;
+ UINT32 Sha1MaxBytes;
+ TCM_DIGEST NewPCRValue;
+ TCG_PEI_CALLBACK_CONTEXT Context;
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgCommonSha1Start( &Context, TCG_ALG_SHA, &Sha1MaxBytes );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgCommonSha1Update(
+ &Context,
+ HashData,
+ HashDataLen,
+ Sha1MaxBytes
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ HashData += (HashDataLen & ~63);
+ HashDataLen &= 63;
+
+ Status = TcmCommonSha1CompleteExtend(
+ &Context,
+ HashData,
+ HashDataLen,
+ NewEvent->PCRIndex,
+ &NewEvent->Digest,
+ &NewPCRValue
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcmPeiLogEvent( This, PeiServices, NewEvent, EventNum );
+
+Exit:
+ return Status;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgPeiPassThroughToTcm
+//
+// Description: TCGPEI common function to abstract passing commands to the TPM
+// FIFO
+//
+// Input: IN *This
+// IN **PeiServices
+// IN TpmInputParameterBlockSize
+// IN *TpmInputParameterBlock
+// IN TpmOutputParameterBlockSize
+// IN *TpmOutputParameterBlock
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiPassThroughToTcm(
+ IN PEI_TCM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT32 TpmInputParameterBlockSize,
+ IN UINT8 *TpmInputParameterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock )
+{
+ EFI_STATUS Status;
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+ TCG_PEI_CALLBACK_CONTEXT Context;
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ InBuffer[0].Buffer = TpmInputParameterBlock;
+ InBuffer[0].Size = TpmInputParameterBlockSize;
+ OutBuffer[0].Buffer = TpmOutputParameterBlock;
+ OutBuffer[0].Size = TpmOutputParameterBlockSize;
+
+ return TcgCommonPassThrough(
+ &Context,
+ sizeof (InBuffer) / sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer
+ );
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgPeiEntry
+//
+// Description: Entry point to Memory Absent and Memory Present Initialization
+// for TPM
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgTcmPeiMemoryCallbackEntry(
+ IN EFI_PEI_SERVICES **PeiServices
+)
+{
+ EFI_PEI_PPI_DESCRIPTOR *PpiDesc;
+ PEI_TCG_PPI *TcgPpi;
+ EFI_STATUS Status;
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gPeiTcgTcmPpiGuid,
+ 0,
+ &PpiDesc,
+ &TcgPpi);
+
+
+ Status = (*PeiServices)->ReInstallPpi(
+ PeiServices,
+ PpiDesc,
+ &mTcgTcgPpiList[0] );
+
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gPeiTcgTcmPpiGuid,
+ 0,
+ &PpiDesc,
+ &TcgPpi );
+
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ return Status;
+}
+
+
diff --git a/Core/EM/TCG2/Common/TcgTisPei.c b/Core/EM/TCG2/Common/TcgTisPei.c
new file mode 100644
index 0000000..d075938
--- /dev/null
+++ b/Core/EM/TCG2/Common/TcgTisPei.c
@@ -0,0 +1,538 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TcgPei.c
+
+ Abstract:
+
+ PEIM that provides TCG services
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgTisPei.c 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgTisPei.c $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 3 3/17/14 3:05p Fredericko
+//
+// 2 3/11/14 6:32p Fredericko
+// [TAG] EIP151925
+// [Category] New Feature
+// [Description] Changes for TcgGeneric Regression Testing
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 1:52p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 57 1/12/12 12:10p Fredericko
+// Remove unused functions.
+//
+// 56 8/26/11 1:01p Fredericko
+//
+// 55 8/09/11 6:15p Fredericko
+// [TAG] EIP66465
+// [Category] New Feature
+// [Description] 1. Added support to remove EFI_EV_ACTION from the TCG
+// logs if customer wants.
+// [Files] 1. Tcgdxe.c
+// 2. Tcgpei.c
+// 3. Tcg.sdl
+//
+// 54 3/31/11 4:49p Fredericko
+// Changes for TCG_LEGACY support
+//
+// 53 3/29/11 12:57p Fredericko
+//
+// 52 3/28/11 2:12p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 50 8/04/10 5:16p Fredericko
+// Changes to flow of Lock Physical Presence for support Smi PPI changes
+//
+// 49 5/21/10 4:31p Fredericko
+// Changes for some build errors that happened with MOR support
+//
+// 48 5/19/10 5:51p Fredericko
+// Updated AMI Function Headers
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgPei.c
+//
+// Description:
+// Functions for early initialization of TPM are executed here
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include "TcgCommon.h"
+#include <AmiPeiLib.h>
+#include <Sha.h>
+#include <TcgMisc.h>
+#include <token.h>
+#include <TpmLib.h>
+#include <TcgPc.h>
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+#include "PPI\CpuIo.h"
+#include "PPI\LoadFile.h"
+#include <FFS.h>
+#include <ppi\AmiTcgPlatformPpi.h>
+#include "TcgPlatformSetupPeiPolicy.h"
+
+
+//*********************************************************************
+// GLOBAL DEFINITIONS
+//*********************************************************************
+
+#pragma pack(1)
+typedef struct _TCG_PEI_CALLBACK_CONTEXT
+{
+ PEI_TPM_PPI *TpmDevice;
+ EFI_PEI_SERVICES **PeiServices;
+} TCG_PEI_CALLBACK_CONTEXT;
+#pragma pack()
+
+EFI_GUID gEfiPeiAmiTcgLogHobGuid = EFI_TCG_LOG_HOB_GUID;
+EFI_GUID gPeiTpmPpiGuid = PEI_TPM_PPI_GUID;
+EFI_GUID gPeiTcgPpiGuid = PEI_TCG_PPI_GUID;
+
+static BOOLEAN SupportType = 0xff;
+
+
+EFI_STATUS
+__stdcall Tcg20CommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PcrIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue,
+ IN UINT8 DigestSize);
+
+UINTN FindNextLogLocation(TCG_PCR_EVENT_HDR *TcgLog, UINTN EventNum);
+
+
+
+static
+EFI_STATUS
+__stdcall FillCallbackContext(
+ IN EFI_PEI_SERVICES **PeiService,
+ OUT TCG_PEI_CALLBACK_CONTEXT *CallbackContext )
+{
+ CallbackContext->PeiServices = PeiService;
+ return (*PeiService)->LocatePpi(
+ PeiService,
+ &gPeiTpmPpiGuid,
+ 0,
+ NULL,
+ &CallbackContext->TpmDevice
+ );
+}
+
+
+UINT8 GetHashPolicy(IN EFI_PEI_SERVICES **PeiServices)
+{
+ TCG_PLATFORM_SETUP_INTERFACE *TcgPeiPolicy = NULL;
+ EFI_STATUS Status;
+ EFI_GUID gTcgPeiPolicyGuid = TCG_PLATFORM_SETUP_PEI_POLICY_GUID;
+ TCG_CONFIGURATION Configuration;
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gTcgPeiPolicyGuid,
+ 0, NULL,
+ &TcgPeiPolicy);
+
+ if(EFI_ERROR(Status) || TcgPeiPolicy == NULL )return 0;
+
+ TcgPeiPolicy->getTcgPeiPolicy(PeiServices, &Configuration);
+ return(Configuration.Reserved1);
+}
+
+
+
+EFI_STATUS
+EFIAPI TcgPeiGetEventLog(
+ IN EFI_PEI_SERVICES **PeiServices,
+ OUT TCG_LOG_HOB **EventLog )
+{
+ EFI_STATUS Status;
+ VOID *HobStart;
+
+ Status = (*PeiServices)->GetHobList( PeiServices, &HobStart );
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ return GetNextGuidHob( &HobStart, &gEfiPeiAmiTcgLogHobGuid, EventLog, NULL );
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Name: TcgPeiLogEvent
+//
+// Description: TCGPEI common function to Hash, Log and Extend data
+// using software SHA-1
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *Event,
+// IN *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiLogEvent(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN TCG_PCR_EVENT *Event,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status = EFI_SUCCESS;
+ TCG_LOG_HOB *TcgLog;
+ TCG_PEI_CALLBACK_CONTEXT Context;
+ UINT8 HashAlgo = GetHashPolicy(PeiServices);
+ UINTN NextLocation;
+
+
+ //only log events if TPM is not deactivated
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(Event->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ Status = TcgPeiGetEventLog( PeiServices, &TcgLog );
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ //prepare next location
+ NextLocation = FindNextLogLocation((TCG_PCR_EVENT_HDR*)(TcgLog + 1), TcgLog->EventNum);
+
+ Status = TcgCommonLogEvent(
+ &Context,
+ (TCG_PCR_EVENT*)(NextLocation),
+ &TcgLog->TableSize,
+ TcgLog->TableMaxSize,
+ Event, HashAlgo);
+
+ if ( EFI_ERROR( Status )){
+ goto Exit;
+ }
+
+ *EventNum = TcgLog->EventNum;
+ TcgLog->EventNum++;
+
+Exit:
+ return Status;
+}
+
+
+
+EFI_STATUS
+__stdcall TcgPeiCommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PCRIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue )
+{
+ TPM_1_2_CMD_HEADER cmdHeader;
+ TPM_1_2_RET_HEADER retHeader;
+ TPM_TRANSMIT_BUFFER InBuffer[3], OutBuffer[2];
+
+ if(SupportType==1){
+ if(GetHashPolicy(((TCG_PEI_CALLBACK_CONTEXT *)CallbackContext)->PeiServices) ==0 ){
+ return(Tcg20CommonExtend(CallbackContext, PCRIndex, Digest, NewPCRValue, 20));
+ }else{
+ return(Tcg20CommonExtend(CallbackContext, PCRIndex, Digest, NewPCRValue, 32));
+ }
+ }
+
+ InBuffer[0].Buffer = &cmdHeader;
+ InBuffer[0].Size = sizeof (cmdHeader);
+ InBuffer[1].Buffer = &PCRIndex;
+ InBuffer[1].Size = sizeof (PCRIndex);
+ InBuffer[2].Buffer = Digest->digest;
+ InBuffer[2].Size = sizeof (Digest->digest);
+
+ OutBuffer[0].Buffer = &retHeader;
+ OutBuffer[0].Size = sizeof (retHeader);
+ OutBuffer[1].Buffer = NewPCRValue->digest;
+ OutBuffer[1].Size = sizeof (NewPCRValue->digest);
+
+ cmdHeader.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdHeader.ParamSize = TPM_H2NL(sizeof (cmdHeader)
+ + sizeof (PCRIndex) + sizeof (Digest->digest));
+
+ cmdHeader.Ordinal = TPM_H2NL( TPM_ORD_Extend );
+ PCRIndex = TcgCommonH2NL( PCRIndex );
+
+ return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer );
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgPeiHashLogExtendEventSW
+// Description: TCGPEI Software function to Hash, Log and Extend data
+// using software SHA-1
+//
+// Input: IN *This
+// IN **PeiServices
+// IN *HashData
+// IN HashDataLen
+// IN OUT *NewEvent,
+// OUT *EventNum
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//*********************************************************************
+EFI_STATUS TcgPeiHashLogExtendEventSW(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 *HashData,
+ IN UINT32 HashDataLen,
+ IN OUT TCG_PCR_EVENT *NewEvent,
+ OUT UINT32 *EventNum )
+{
+ EFI_STATUS Status;
+ TCG_DIGEST NewPCRValue;
+ TCG_PEI_CALLBACK_CONTEXT Context;
+ EFI_GUID Tpm20Hobguid = TPM20_HOB_GUID;
+ AMI_TPM20SUPPORTTYPE_PPI *Tpm20PeiSupportPpi = NULL;
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+#if defined LOG_EV_EFI_ACTION && LOG_EV_EFI_ACTION == 0
+ if(NewEvent->EventType == EV_EFI_ACTION)
+ {
+ return EFI_SUCCESS;
+ }
+#endif
+
+ if(GetHashPolicy( PeiServices)==0)
+ {
+ Status = SHA1HashAll( &Context, HashData, HashDataLen, &NewEvent->Digest );
+ }else{
+ //Status = SHA2HashAll(&Context, HashData, HashDataLen, &NewEvent->Digest);
+ }
+
+ if ( EFI_ERROR( Status ))
+ {
+ return Status;
+ }
+
+ Status = Context.TpmDevice->Init( Context.TpmDevice, PeiServices );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ if(SupportType == 0xff)
+ {
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &Tpm20Hobguid,
+ 0, NULL,
+ &Tpm20PeiSupportPpi);
+
+ if(!EFI_ERROR(Status) && Tpm20PeiSupportPpi!= NULL){
+ SupportType = 1;
+ }else{
+ SupportType = 0;
+ }
+ }
+
+ Status = TcgPeiCommonExtend(
+ &Context,
+ NewEvent->PCRIndex,
+ &NewEvent->Digest,
+ &NewPCRValue
+ );
+
+ if ( EFI_ERROR( Status ))
+ {
+ goto Exit;
+ }
+
+ Status = TcgPeiLogEvent( This, PeiServices, NewEvent, EventNum );
+
+Exit:
+ Context.TpmDevice->Close( Context.TpmDevice, PeiServices );
+ return Status;
+}
+
+
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TcgPeiPassThroughToTpm
+//
+// Description: TCGPEI common function to abstract passing commands to the TPM
+// FIFO
+//
+// Input: IN *This
+// IN **PeiServices
+// IN TpmInputParameterBlockSize
+// IN *TpmInputParameterBlock
+// IN TpmOutputParameterBlockSize
+// IN *TpmOutputParameterBlock
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiPassThroughToTpm(
+ IN PEI_TCG_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT32 TpmInputParameterBlockSize,
+ IN UINT8 *TpmInputParameterBlock,
+ IN UINT32 TpmOutputParameterBlockSize,
+ IN UINT8 *TpmOutputParameterBlock )
+{
+ EFI_STATUS Status;
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+ TCG_PEI_CALLBACK_CONTEXT Context;
+
+ Status = FillCallbackContext( PeiServices, &Context );
+ ASSERT_PEI_ERROR( PeiServices, Status );
+
+ InBuffer[0].Buffer = TpmInputParameterBlock;
+ InBuffer[0].Size = TpmInputParameterBlockSize;
+ OutBuffer[0].Buffer = TpmOutputParameterBlock;
+ OutBuffer[0].Size = TpmOutputParameterBlockSize;
+
+ return TcgCommonPassThrough(
+ &Context,
+ sizeof (InBuffer) / sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer
+ );
+}
+
+
+static PEI_TCG_PPI mTcgPpi = {
+ TcgPeiHashLogExtendEventSW,
+ TcgPeiLogEvent,
+ TcgPeiPassThroughToTpm
+};
+
+static EFI_PEI_PPI_DESCRIPTOR mTcgPpiList[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTcgPpiGuid,
+ &mTcgPpi
+ }
+};
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TcgPeiEntry
+//
+// Description: Entry point to Memory Absent and Memory Present Initialization
+// for TPM
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiEntry(
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS TPM_Base = (EFI_PHYSICAL_ADDRESS)PORT_TPM_IOMEMBASE;
+#if TCG_LEGACY == 0
+ Status = IsTpmPresent((TPM_1_2_REGISTERS_PTR)( UINTN ) TPM_Base );
+ if(EFI_ERROR(Status))return Status;
+#endif
+ Status = (*PeiServices)->InstallPpi( PeiServices, mTcgPpiList );
+ return Status;
+}
diff --git a/Core/EM/TCG2/Common/TisPei.c b/Core/EM/TCG2/Common/TisPei.c
new file mode 100644
index 0000000..ded01a7
--- /dev/null
+++ b/Core/EM/TCG2/Common/TisPei.c
@@ -0,0 +1,691 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TpmPei.h
+
+ Abstract:
+
+ PEI driver for TPM devices
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TisPei.c 2 4/21/14 3:16p Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 4/21/14 3:16p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TisPei.c $
+//
+// 2 4/21/14 3:16p Fredericko
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 17 4/01/11 11:13a Fredericko
+//
+// 16 4/01/11 10:52a Fredericko
+// Changes for TPM support in Legacy IO mode. Some TPMs do not allow init
+// function to be called more than once during legacy mode.
+//
+// 15 3/31/11 4:49p Fredericko
+// Changes for TCG_LEGACY support
+//
+// 14 3/29/11 12:57p Fredericko
+//
+// 13 3/28/11 2:06p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 12 5/19/10 5:44p Fredericko
+// Included File Header
+// Included File Revision History
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TpmPei.c
+//
+// Description:
+// Abstracted functions for Tpm ppis' are defined here
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include <Pei.h>
+#include <TcgTpm12.h>
+#include <TpmLib.h>
+#include <AmiPeiLib.h>
+#include <token.h>
+#include "TcgCommon.h"
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+#include "Tpm20CRBLib.h"
+
+
+#define _CR( Record, TYPE,\
+ Field )((TYPE*) ((CHAR8*) (Record) - (CHAR8*) &(((TYPE*) 0)->Field)))
+
+#define INTEL_VID 0x8086
+#define TCG_VID_OFFSET 0x0F00
+
+BOOLEAN iTPMVerifyMeStatus( );
+
+#define TPM_PEI_PRIVATE_DATA_FROM_THIS( This ) \
+ _CR( This, TPM_PEI_PRIVATE_DATA, TpmPpi )
+
+typedef struct _TPM_PEI_PRIVATE_DATA
+{
+ PEI_TPM_PPI TpmPpi;
+ EFI_PHYSICAL_ADDRESS BaseAddr;
+} TPM_PEI_PRIVATE_DATA;
+
+#if TCG_LEGACY == 1
+
+typedef struct _TPM_PEI_CALLBACK
+{
+ EFI_PEI_NOTIFY_DESCRIPTOR NotifyDesc;
+ EFI_FFS_FILE_HEADER *FfsHeader;
+
+} TPM_PEI_CALLBACK;
+
+
+VOID TpmPeiCallMPDriver(IN EFI_PEI_SERVICES **PeiServices, IN UINT8 CFuncID,
+ TPMTransmitEntryStruct *CData, UINT32* OUT CRetVal);
+
+EFI_GUID gTpmCallbackguid = AMI_TPM_LEGACY_GUID;
+#endif
+
+
+#if TCG_LEGACY == 0
+EFI_STATUS
+EFIAPI TpmPeiInit(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ TPM_PEI_PRIVATE_DATA *Private;
+
+ Private = TPM_PEI_PRIVATE_DATA_FROM_THIS( This );
+ return TisRequestLocality(
+ (TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr);
+}
+
+EFI_STATUS
+EFIAPI TpmPeiClose(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ TPM_PEI_PRIVATE_DATA *Private;
+
+ Private = TPM_PEI_PRIVATE_DATA_FROM_THIS( This );
+ return TisReleaseLocality(
+ (TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr);
+}
+
+EFI_STATUS
+EFIAPI TpmPeiGetStatusInfo(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI TpmPeiTransmit(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers )
+{
+ TPM_PEI_PRIVATE_DATA *Private;
+ TPM_1_2_REGISTERS_PTR TpmReg;
+
+ Private = TPM_PEI_PRIVATE_DATA_FROM_THIS( This );
+ TpmReg = (TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr;
+ return TpmLibPassThrough(
+ TpmReg,
+ NoInputBuffers,
+ InputBuffers,
+ NoOutputBuffers,
+ OutputBuffers
+ );
+}
+
+
+EFI_STATUS
+EFIAPI CrbTpmPeiInit(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI CrbTpmPeiClose(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI CrbTpmPeiGetStatusInfo(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI CrbTpmPeiTransmit(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers )
+{
+ return EFI_UNSUPPORTED;
+}
+#else
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTpmPeiInit
+//
+// Description: Call to OEM driver to initialize TPM
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TpmPeiInit(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_SUCCESS;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTpmPeiClose
+//
+// Description: Call to OEM driver to Close TPM
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TpmPeiClose(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+EFIAPI TpmPeiGetStatusInfo(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTpmPeiSHA1Setup
+//
+// Description: Helper function to help with Command transmission to TPM
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+// IN UINTN NoInputBuffers
+// IN TPM_TRANSMIT_BUFFER *InputBuffers
+// IN OUT void **Buffer
+// IN UINT8 *SHA_ARRAY
+//
+// Output: BOOLEAN
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+BOOLEAN
+EFIAPI TpmPeiSHA1Setup(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN OUT void **Buffer,
+ IN UINT8 *SHA_ARRAY )
+{
+ TPM_1_2_CMD_HEADER *SHA1HeaderCheck;
+ void *Context = NULL;
+ UINT8 i = 0, loc = 0;
+
+ //check if this an SHA1 update or Complete call and set the buffer
+ //else no need to update the buffer is the same
+ SHA1HeaderCheck = (TPM_1_2_CMD_HEADER*)InputBuffers->Buffer;
+
+ if ( SHA1HeaderCheck->Ordinal !=
+ TPM_H2NL(TPM_ORD_SHA1CompleteExtend ) && SHA1HeaderCheck->Ordinal !=
+ TPM_H2NL( TPM_ORD_SHA1Update ) && SHA1HeaderCheck->Ordinal != TPM_H2NL(TPM_ORD_Extend))
+ {
+ //no need to modify buffers just pass it through
+ return FALSE;
+ }
+
+ if ( NoInputBuffers > 1 )
+ {
+ //if we get here it means the buffer needs to be modified!
+ for (; i < NoInputBuffers; i++ )
+ {
+ TcgCommonCopyMem( Context,
+ &SHA_ARRAY[loc],
+ InputBuffers[i].Buffer,
+ InputBuffers[i].Size );
+
+ loc += InputBuffers[i].Size;
+ }
+ }
+ else {
+ return FALSE;
+ }
+
+ *Buffer = SHA_ARRAY;
+ return TRUE;
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EMpTpmPeiTransmit
+//
+// Description: TPM Transmit function
+//
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices,
+// IN UINTN NoInputBuffers,
+// IN TPM_TRANSMIT_BUFFER *InputBuffers,
+// IN UINTN NoOutputBuffers,
+// IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TpmPeiTransmit(
+ IN PEI_TPM_PPI *This,
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers )
+{
+ TPM_PEI_PRIVATE_DATA *Private;
+ TPMTransmitEntryStruct FillESI;
+ UINT8 FuncID = MP_FUNCTION_TRANSMIT;
+ UINT32 Ret;
+ void *buffer;
+ UINT8 SHA_ARRAY[INTERNAL_SHA_ARRAY_LENGTH];
+ UINT8 SHA_ARRAY_OUT[INTERNAL_SHA_ARRAY_LENGTH];
+ BOOLEAN FillBuff = FALSE;
+ void *Context = NULL;
+ UINT8 i = 0;
+ UINT8 loc = 0;
+
+
+ if ( !TpmPeiSHA1Setup( This, PeiServices, NoInputBuffers, InputBuffers,
+ &buffer, SHA_ARRAY ))
+ {
+ FillESI.pbInBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)InputBuffers->Buffer;
+ FillESI.dwInLen = (UINT32)InputBuffers->Size;
+ FillESI.pbOutBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)OutputBuffers->Buffer;
+ FillESI.dwOutLen = (UINT32)OutputBuffers->Size;
+ }
+ else {
+ FillESI.pbInBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)SHA_ARRAY;
+ FillESI.dwInLen = 0;
+
+ for (; i < NoInputBuffers; i++ )
+ {
+ FillESI.dwInLen += (UINT32)InputBuffers[i].Size;
+ }
+ i = 0;
+ FillESI.pbOutBuf = (UINT32)(EFI_PHYSICAL_ADDRESS)SHA_ARRAY_OUT;
+ FillBuff = TRUE;
+ FillESI.dwOutLen = 0;
+
+ for (; i < NoOutputBuffers; i++ )
+ {
+ FillESI.dwOutLen += OutputBuffers[i].Size;
+ }
+ }
+
+ Private = TPM_PEI_PRIVATE_DATA_FROM_THIS( This );
+ TpmPeiCallMPDriver( PeiServices, FuncID, &FillESI, &Ret );
+
+ if ( FillBuff ) //setup output buffer for the interface
+ {
+ i = 0;
+ for (; i < NoOutputBuffers; i++ )
+ {
+ TcgCommonCopyMem( Context,
+ OutputBuffers[i].Buffer,
+ &SHA_ARRAY_OUT[loc],
+ OutputBuffers[i].Size );
+
+ loc += OutputBuffers[i].Size;
+ }
+ }
+ return EFI_SUCCESS;
+}
+
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: TpmPeiCallMPDriver
+//
+// Description: Interface to performing MP driver function calls in PEI
+// Uses _ASM directives. Return Value in EAX return as status
+//
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+// IN UINT8 CFuncID,
+// IN TPMTransmitEntryStruct * CData,
+// OUT UINT32* CRetVal
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+VOID TpmPeiCallMPDriver(
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN UINT8 CFuncID,
+ TPMTransmitEntryStruct * CData,
+ UINT32* OUT CRetVal )
+{
+ UINT32 ReturnVal;
+ FAR32LOCALS CommonLegX;
+ EFI_GUID guidMA = EFI_TCG_MADriver_HOB_GUID;
+ EFI_GUID guidMP = EFI_TCG_MPDriver_HOB_GUID;
+ ESPFUNCSTRUCT EspStruct;
+ VOID *Temp = &ReturnVal;
+ MASTRUCT MA;
+ UINT32 MAStart;
+ UINT32 EspVal;
+
+
+ TPMTransmitEntryStruct IntCData = *CData;
+ UINT32 Address = (UINT32)&IntCData;
+
+ CommonLegX.Offset = 0;
+ CommonLegX.Selector = 0;
+
+ if (((UINT32)Temp & (UINT32)0xff000000) == (UINT32)0xff000000 )
+ {
+ FillDriverLoc( &MA.Offset, PeiServices, &guidMA );
+ MAStart = MA.Offset - MA.Codep;
+ CommonLegX.Offset = MA.Offset;
+ CommonLegX.Selector = SEL_flatCS;
+ Temp = &EspStruct;
+
+ if ( CommonLegX.Offset == NULL )
+ {
+ return;
+ }
+
+ _asm {
+ //fill esp
+ push esi
+ mov esi, [ReturnAdd]
+ mov [EspStruct.ReturnAddress], esi
+ mov esi, [MAStart]
+ mov [EspStruct.Header], esi
+ pop esi
+ mov EspVal, esp // Save ESP
+ mov al, [CFuncID]
+ mov [EspStruct.FuncNum], al
+ mov esp, Temp
+ call fword ptr [CommonLegX]
+ mov esp, EspVal // Restore ESP
+ReturnAdd:
+ mov ReturnVal, eax
+ }
+
+ *CRetVal = ReturnVal;
+ return;
+ }
+ else {
+ FillDriverLoc( &CommonLegX.Offset, PeiServices, &guidMP );
+ CommonLegX.Selector = SEL_flatCS;
+
+ _asm {
+ xor eax, eax
+ mov al, [CFuncID]
+ cmp eax, MP_FUNCTION_TRANSMIT
+ jnz Empty_Buff
+ mov ESI, Address
+Empty_Buff:
+ mov EspVal, esp // Save ESP
+ call fword ptr [CommonLegX];
+ mov ReturnVal, eax
+ mov esp, EspVal // Restore ESP
+
+ }
+ *CRetVal = ReturnVal;
+ }
+}
+
+#endif
+
+static TPM_PEI_PRIVATE_DATA mTpmPrivate = {
+ {
+ TpmPeiInit,
+ TpmPeiClose,
+ TpmPeiGetStatusInfo,
+ TpmPeiTransmit
+ },
+ TPM_BASE_ADDRESS
+};
+
+static TPM_PEI_PRIVATE_DATA CrbmTpmPrivate = {
+ {
+ CrbTpmPeiInit,
+ CrbTpmPeiClose,
+ CrbTpmPeiGetStatusInfo,
+ CrbTpmPeiTransmit
+ },
+ TPM_BASE_ADDRESS
+};
+
+
+
+#if TCG_LEGACY == 1
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: InitLegacyTpmEntry
+//
+// Description: Entry point for TPM initialization after memory is installed
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI InitLegacyTpmEntry(
+IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
+ IN VOID *Ppi)
+{
+ UINT8 FuncID;
+ TPMTransmitEntryStruct EmptyBuf;
+ UINT32 Ret;
+
+ FuncID = MA_FUNCTION_INIT;
+ TpmPeiCallMPDriver( PeiServices, FuncID, &EmptyBuf, &Ret );
+ if ( !Ret )
+ {
+ return EFI_SUCCESS;
+ }
+ return EFI_DEVICE_ERROR;
+}
+#endif
+
+
+static EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTpmPpiGuid,
+ &mTpmPrivate.TpmPpi
+};
+
+static EFI_PEI_PPI_DESCRIPTOR mCrbPpiList[] = {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTpmPpiGuid,
+ &CrbmTpmPrivate.TpmPpi
+};
+
+
+
+
+EFI_STATUS
+EFIAPI TpmPeiEntry(
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ EFI_STATUS Status=EFI_NOT_FOUND;
+ BOOLEAN Temp = TRUE;
+#if TCG_LEGACY == 1
+ TPM_PEI_CALLBACK *Callback;
+#endif
+
+ if(!isTpm20CrbPresent()) (*PeiServices)->InstallPpi( PeiServices, mPpiList );
+
+#if TCG_LEGACY == 1
+ Status = (**PeiServices).AllocatePool(
+ PeiServices,
+ sizeof (TPM_PEI_CALLBACK),
+ &Callback);
+
+ if ( !EFI_ERROR( Status ))
+ {
+ Callback->NotifyDesc.Flags
+ = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
+ Callback->NotifyDesc.Guid = &gTpmCallbackguid;
+ Callback->NotifyDesc.Notify = InitLegacyTpmEntry;
+ Callback->FfsHeader = FfsHeader;
+
+ Status = (*PeiServices)->NotifyPpi( PeiServices,
+ &Callback->NotifyDesc );
+ }
+ return EFI_SUCCESS;
+#endif
+
+ if ( Temp )
+ {
+ Status = IsTpmPresent((TPM_1_2_REGISTERS_PTR)(
+ UINTN ) mTpmPrivate.BaseAddr );
+
+ if ( EFI_ERROR( Status ))
+ {
+ if(!isTpm20CrbPresent())return Status;
+ else{
+ Status = (*PeiServices)->InstallPpi( PeiServices, mCrbPpiList );
+ return Status;
+ }
+ }
+ }
+
+ return Status;
+} \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/Tpm20Includes/Tpm20.h b/Core/EM/TCG2/Common/Tpm20Includes/Tpm20.h
new file mode 100644
index 0000000..9ba9d3e
--- /dev/null
+++ b/Core/EM/TCG2/Common/Tpm20Includes/Tpm20.h
@@ -0,0 +1,1917 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/CommonHeaders/Tpm20Includes/Tpm20.h 2 6/14/14 12:25a Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 6/14/14 12:25a $
+//*************************************************************************
+// Revision History
+// ----------------
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: Tpm20.h.h
+//
+// Description:
+// Contains Industry Standard #defines and Structures for TPM20
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TPM20_H_
+#define _TPM20_H_
+
+#include <efi.h>
+
+#pragma pack (push)
+#pragma pack (1)
+
+
+#ifdef TRUE
+#undef TRUE
+#endif
+
+#ifdef FALSE
+#undef FALSE
+#endif
+
+// Table 189 -- Hash Algorithm Digest and Block Size Values
+#define SHA1_DIGEST_SIZE 20 // 20
+#define SHA1_BLOCK_SIZE 64 // 64
+#define SHA256_DIGEST_SIZE 32 // 32
+#define SHA256_BLOCK_SIZE 64 // 64
+#define SM3_256_DIGEST_SIZE 32 // 32
+#define SM3_256_BLOCK_SIZE 64 // 64
+#define SHA384_DIGEST_SIZE 48 // 48
+#define SHA384_BLOCK_SIZE 128 // 128
+#define SHA512_DIGEST_SIZE 64 // 64
+#define SHA512_BLOCK_SIZE 128 // 128
+#define WHIRLPOOL512_DIGEST_SIZE 64 // 64
+#define WHIRLPOOL512_BLOCK_SIZE 64 // 64
+
+
+// Table 190 -- Logic Values
+#define YES 1 // 1
+#define NO 0 // 0
+#define TRUE 1 // 1
+#define FALSE 0 // 0
+#define SET 1 // 1
+#define CLEAR 0 // 0
+
+
+// Table 191 -- Processor Values
+#define BIG_ENDIAN 0 // NO
+#define LITTLE_ENDIAN 1 // YES
+
+
+// Table 192 -- Implemented Algorithms
+#define RSA 1 // YES
+#define DES 0 // NO
+#define _3DES 0 // NO
+#define SHA1 1 // YES
+#define SHA 1 // SHA1
+#define HMAC 1 // YES
+#define AES 1 // YES
+#define CFB 1 // YES
+#define MGF1 1 // YES
+#define XOR 1 // YES
+#define KEYEDHASH 1 // YES
+#define SHA256 1 // YES
+#define SHA384 1 // YES
+#define SHA512 0 // NO
+#define WHIRLPOOL512 0 // NO
+#define SM3_256 0 // NO
+#define SMS4 0 // NO
+#define RSASSA_PKCS1v1_5 1 // RSA
+#define RSAES_PKCS1v1_5 1 // RSA
+#define PSS 1 // RSA
+#define OAEP 1 // RSA
+#define ECC 1 // YES
+#define ECDSA 1 // ECC
+#define KDF1_SP800_56a 1 // ECC
+#define KDF2 0 // NO
+#define KDF1_SP800_108 1 // YES
+#define CTR 1 // YES
+#define OFB 1 // YES
+#define CBC 1 // YES
+#define ECB 1 // YES
+
+
+// Table 193 -- Implemented Algorithm Constants
+#define MAX_RSA_KEY_BYTES 256 // 2048/8
+#define MAX_ECC_KEY 48 // 384/8
+#define MAX_CONTEXT_SIZE 4096 // 4096
+#define AES_KEY_SIZE_256 256 // 256
+#define MAX_AES_KEY 32 // 256/8
+#define RSA_KEY_SIZE_2048 2048 // 2048
+#define MAX_CC_LIST_SIZE 8 // 8
+#define MAX_HASH_BLOCK 128 // 128
+
+
+// Table 194 -- Implementation Values
+#define IMPLEMENTATION_PCR 24 // 24
+#define PLATFORM_PCR 24 // 24
+#define DRTM_PCR (TPM_RH_PCR0+17) // (TPM_RH_PCR0+17)
+#define NUM_LOCALITIES 5 // 5
+#define MAX_ACTIVE_SESSIONS 64 // 64
+#define CONTEXT_SLOT UINT16 // UINT16
+#define CONTEXT_COUNTER UINT64 // UINT64
+#define MAX_LOADED_SESSIONS 3 // 3
+#define MAX_LOADED_OBJECTS 3 // 3
+#define MAX_EVICT_OBJECTS 16 // 16
+#define HASH_COUNT 3 // (SHA1+SHA256+SHA384+SHA512+SM3_256)
+#define SYM_COUNT 2 // (XOR+AES+SMS4)
+#define ASYM_COUNT 2 // (RSA+ECC)
+#define PCR_SELECT_MIN 3 // ((PLATFORM_PCR+7)/8)
+#define PCR_SELECT_MAX 3 // ((IMPLEMENTATION_PCR+7)/8)
+#define MAX_DIGEST_BUFFER 1024 // 1024
+#define MAX_NV_INDEX_SIZE 1024 // 1024
+#define MAX_CAP_BUFFER 1024 // 1024
+#define MAX_CAP_DATA (MAX_CAP_BUFFER-sizeof(TPM_CAP)-sizeof(UINT32)) // (MAX_CAP_BUFFER-sizeof(TPM_CAP)-sizeof(UINT32))
+#define MAX_CAP_ALGS (MAX_CAP_DATA/sizeof(TPMS_ALG_PROPERTY)) // (MAX_CAP_DATA/sizeof(TPMS_ALG_PROPERTY))
+#define MAX_CAP_HANDLES (MAX_CAP_DATA/sizeof(TPM_HANDLE)) // (MAX_CAP_DATA/sizeof(TPM_HANDLE))
+#define MAX_CAP_CC (MAX_CAP_DATA/sizeof(TPM_CC)) // (MAX_CAP_DATA/sizeof(TPM_CC))
+#define MAX_TPM_PROPERTIES (MAX_CAP_DATA/sizeof(TPMS_TAGGED_PROPERTY)) // (MAX_CAP_DATA/sizeof(TPMS_TAGGED_PROPERTY))
+#define MAX_PCR_PROPERTIES (MAX_CAP_DATA/sizeof(TPMS_TAGGED_PCR_SELECT)) // (MAX_CAP_DATA/sizeof(TPMS_TAGGED_PCR_SELECT))
+#define MAX_ECC_CURVES (MAX_CAP_DATA/sizeof(TPM_ECC_CURVE_ID)) // (MAX_CAP_DATA/sizeof(TPM_ECC_CURVE_ID))
+#define NV_MEMORY_SIZE 8192 // 8192
+#define NUM_STATIC_PCR 16 // 16
+#define MAX_ALG_LIST_SIZE 128 // 128
+#define NV_CLOCK_UPDATE_RATE 12 // 12
+#define TIMER_PRESCALE 100000 // 100000
+#define PP_COMMANDS_NUM 16 // 16
+#define PROOF_SIZE 32 // 32
+#define PRIMARY_SEED_SIZE 64 // 64
+#define CONTEXT_ENCRYPT_ALG TPM_ALG_AES // TPM_ALG_AES
+#define CONTEXT_ENCRYPT_KEYSIZE 128 // 128
+#define CONTEXT_INTEGRITY_HASH_ALG TPM_ALG_SHA256 // TPM_ALG_SHA256
+#define CONTEXT_INTEGRITY_HASH_SIZE 32 // 32
+#define NV_CLOCK_UPDATE_INTERVAL 12 // 12
+#define GENERATION_CTR UINT8 // UINT8
+#define NUM_POLICY_PCR 1 // 1
+#define MAX_COMMAND_SIZE 4096 // 4096
+#define MAX_RESPONSE_SIZE 4096 // 4096
+#define MAX_ORDERLY_COUNT 256 // 256
+#define ALG_ID_FIRST TPM_ALG_RSA // TPM_ALG_RSA
+#define ALG_ID_LAST TPM_ALG_ECB // TPM_ALG_ECB
+#define MAX_SYM_DATA 128 // 128
+#define MAX_HASH_STATE_SIZE 400 // 400
+#define MAX_HMAC_STATE_SIZE 800 // 800
+
+
+// Table 2 -- BaseTypes from BaseTypes <I/O>
+typedef unsigned char BYTE;
+
+// Table 3 -- DocumentationClarity from outputTypeDef <I/O>
+typedef UINT32 TPM_ALGORITHM_ID;
+typedef UINT32 TPM_MODIFIER_INDICATOR;
+typedef UINT32 TPM_SESSION_OFFSET;
+typedef UINT16 TPM_KEY_SIZE;
+typedef UINT16 TPM_KEY_BITS;
+typedef UINT64 TPM_SYSTEM_ADDRESS;
+
+typedef UINT32 TPM2_PCRINDEX;
+
+// Table 4 -- TPM_GENERATED from outputConstDef <O,S>
+typedef UINT32 TPM_GENERATED;
+
+#define TPM_GENERATED_VALUE (TPM_GENERATED)(0xff544347)
+
+
+
+
+// Table 5 -- TPM2_ALG_ID from outputConstDef <I/O,S>
+typedef UINT16 TPM2_ALG_ID;
+
+
+#define TPM2_ALG_ERROR (TPM2_ALG_ID)(0x0000)
+#define TPM2_ALG_RSA (TPM2_ALG_ID)(0x0001)
+#define TPM2_ALG_DES (TPM2_ALG_ID)(0x0002)
+#define TPM2_ALG__3DES (TPM2_ALG_ID)(0x0003)
+#define TPM2_ALG_SHA (TPM2_ALG_ID)(0x0004)
+#define TPM2_ALG_SHA1 (TPM2_ALG_ID)(0x0004)
+#define TPM2_ALG_HMAC (TPM2_ALG_ID)(0x0005)
+#define TPM2_ALG_AES (TPM2_ALG_ID)(0x0006)
+#define TPM2_ALG_MGF1 (TPM2_ALG_ID)(0x0007)
+#define TPM2_ALG_XOR (TPM2_ALG_ID)(0x000A)
+#define TPM2_ALG_KEYEDHASH (TPM2_ALG_ID)(0x0008)
+#define TPM2_ALG_SHA256 (TPM2_ALG_ID)(0x000B)
+#define TPM2_ALG_SHA384 (TPM2_ALG_ID)(0x000C)
+#define TPM2_ALG_SHA512 (TPM2_ALG_ID)(0x000D)
+#define TPM2_ALG_WHIRLPOOL512 (TPM2_ALG_ID)(0x000E)
+#define TPM2_ALG_NULL (TPM2_ALG_ID)(0x0010)
+#define TPM2_ALG_SM3_256 (TPM2_ALG_ID)(0x0012)
+#define TPM2_ALG_SMS4 (TPM2_ALG_ID)(0x0013)
+#define TPM2_ALG_RSASSA_PKCS1v1_5 (TPM2_ALG_ID)(0x0014)
+#define TPM2_ALG_RSAES_PKCS1v1_5 (TPM2_ALG_ID)(0x0015)
+#define TPM2_ALG_PSS (TPM2_ALG_ID)(0x0016)
+#define TPM2_ALG_OAEP (TPM2_ALG_ID)(0x0017)
+#define TPM2_ALG_ECDSA (TPM2_ALG_ID)(0x0018)
+#define TPM2_ALG_SP800_56a_C1_1 (TPM2_ALG_ID)(0x0019)
+#define TPM2_ALG_KDF1_SP800_56a (TPM2_ALG_ID)(0x0020)
+#define TPM2_ALG_KDF2 (TPM2_ALG_ID)(0x0021)
+#define TPM2_ALG_KDF1_SP800_108 (TPM2_ALG_ID)(0x0022)
+#define TPM2_ALG_ECC (TPM2_ALG_ID)(0x0023)
+#define TPM2_ALG_ECDAA (TPM2_ALG_ID)(0x0024)
+#define TPM2_ALG_CTR (TPM2_ALG_ID)(0x0040)
+#define TPM2_ALG_OFB (TPM2_ALG_ID)(0x0041)
+#define TPM2_ALG_CBC (TPM2_ALG_ID)(0x0042)
+#define TPM2_ALG_CFB (TPM2_ALG_ID)(0x0043)
+#define TPM2_ALG_ECB (TPM2_ALG_ID)(0x0044)
+
+
+// Table 7 -- TPM_CC from outputConstDef <I/O,S>
+typedef UINT32 TPM_CC;
+
+#define TPM_CC_FIRST (TPM_CC)(0x00000120)
+#define TPM_CC_PP_FIRST (TPM_CC)(0x00000120)
+#define TPM_CC_EvictControl (TPM_CC)(0x00000120)
+#define TPM_CC_HierarchyControl (TPM_CC)(0x00000121)
+#define TPM_CC_NV_UndefineSpace (TPM_CC)(0x00000122)
+#define TPM_CC_ChangeEPS (TPM_CC)(0x00000124)
+#define TPM_CC_ChangePPS (TPM_CC)(0x00000125)
+#define TPM_CC_Clear (TPM_CC)(0x00000126)
+#define TPM_CC_ClearControl (TPM_CC)(0x00000127)
+#define TPM_CC_ClockSet (TPM_CC)(0x00000128)
+#define TPM_CC_HierarchyChangeAuth (TPM_CC)(0x00000129)
+#define TPM_CC_NV_DefineSpace (TPM_CC)(0x0000012A)
+#define TPM_CC_PCR_Allocate (TPM_CC)(0x0000012B)
+#define TPM_CC_PCR_SetAuthPolicy (TPM_CC)(0x0000012C)
+#define TPM_CC_PP_Commands (TPM_CC)(0x0000012D)
+#define TPM_CC_SetPrimaryPolicy (TPM_CC)(0x0000012E)
+#define TPM_CC_FieldUpgradeStart (TPM_CC)(0x0000012F)
+#define TPM_CC_ClockRateAdjust (TPM_CC)(0x00000130)
+#define TPM_CC_CreatePrimary (TPM_CC)(0x00000131)
+#define TPM_CC_NV_GlobalWriteLock (TPM_CC)(0x00000132)
+#define TPM_CC_PP_LAST (TPM_CC)(0x00000132)
+#define TPM_CC_GetCommandAuditDigest (TPM_CC)(0x00000133)
+#define TPM_CC_NV_Increment (TPM_CC)(0x00000134)
+#define TPM_CC_NV_SetBits (TPM_CC)(0x00000135)
+#define TPM_CC_NV_Extend (TPM_CC)(0x00000136)
+#define TPM_CC_NV_Write (TPM_CC)(0x00000137)
+#define TPM_CC_NV_WriteLock (TPM_CC)(0x00000138)
+#define TPM_CC_DictionaryAttackLockReset (TPM_CC)(0x00000139)
+#define TPM_CC_DictionaryAttackParameters (TPM_CC)(0x0000013A)
+#define TPM_CC_NV_ChangeAuth (TPM_CC)(0x0000013B)
+#define TPM_CC_PCR_Event (TPM_CC)(0x0000013C)
+#define TPM_CC_PCR_Reset (TPM_CC)(0x0000013D)
+#define TPM_CC_SequenceComplete (TPM_CC)(0x0000013E)
+#define TPM_CC_SetRegion (TPM_CC)(0x0000013F)
+#define TPM_CC_SetCommandCodeAuditStatus (TPM_CC)(0x00000140)
+#define TPM_CC_FieldUpgradeData (TPM_CC)(0x00000141)
+#define TPM_CC_IncrementalSelfTest (TPM_CC)(0x00000142)
+#define TPM_CC_SelfTest (TPM_CC)(0x00000143)
+#define TPM_CC_Startup (TPM_CC)(0x00000144)
+#define TPM_CC_Shutdown (TPM_CC)(0x00000145)
+#define TPM_CC_StirRandom (TPM_CC)(0x00000146)
+#define TPM_CC_ActivateCredential (TPM_CC)(0x00000147)
+#define TPM_CC_Certify (TPM_CC)(0x00000148)
+#define TPM_CC_PolicyNV (TPM_CC)(0x00000149)
+#define TPM_CC_CertifyCreation (TPM_CC)(0x0000014A)
+#define TPM_CC_Duplicate (TPM_CC)(0x0000014B)
+#define TPM_CC_GetTime (TPM_CC)(0x0000014C)
+#define TPM_CC_GetSessionAuditDigest (TPM_CC)(0x0000014D)
+#define TPM_CC_NV_Read (TPM_CC)(0x0000014E)
+#define TPM_CC_NV_ReadLock (TPM_CC)(0x0000014F)
+#define TPM_CC_ObjectChangeAuth (TPM_CC)(0x00000150)
+#define TPM_CC_PolicySecret (TPM_CC)(0x00000151)
+#define TPM_CC_Rewrap (TPM_CC)(0x00000152)
+#define TPM_CC_Create (TPM_CC)(0x00000153)
+#define TPM_CC_ECDH_ZGen (TPM_CC)(0x00000154)
+#define TPM_CC_HMAC (TPM_CC)(0x00000155)
+#define TPM_CC_Import (TPM_CC)(0x00000156)
+#define TPM_CC_Load (TPM_CC)(0x00000157)
+#define TPM_CC_Quote (TPM_CC)(0x00000158)
+#define TPM_CC_RSADP (TPM_CC)(0x00000159)
+#define TPM_CC_RSAES_OAEP_Decrypt (TPM_CC)(0x0000015A)
+#define TPM_CC_HMAC_Start (TPM_CC)(0x0000015B)
+#define TPM_CC_SequenceUpdate (TPM_CC)(0x0000015C)
+#define TPM_CC_Sign (TPM_CC)(0x0000015D)
+#define TPM_CC_Unseal (TPM_CC)(0x0000015E)
+#define TPM_CC_PolicySigned (TPM_CC)(0x00000160)
+#define TPM_CC_ContextLoad (TPM_CC)(0x00000161)
+#define TPM_CC_ContextSave (TPM_CC)(0x00000162)
+#define TPM_CC_ECDH_KeyGen (TPM_CC)(0x00000163)
+#define TPM_CC_EncryptDecrypt (TPM_CC)(0x00000164)
+#define TPM_CC_FlushContext (TPM_CC)(0x00000165)
+#define TPM_CC_LoadPrimary (TPM_CC)(0x00000166)
+#define TPM_CC_LoadExternal (TPM_CC)(0x00000167)
+#define TPM_CC_MakeCredential (TPM_CC)(0x00000168)
+#define TPM_CC_NV_ReadPublic (TPM_CC)(0x00000169)
+#define TPM_CC_PolicyAuthorize (TPM_CC)(0x0000016A)
+#define TPM_CC_PolicyAuthValue (TPM_CC)(0x0000016B)
+#define TPM_CC_PolicyCommandCode (TPM_CC)(0x0000016C)
+#define TPM_CC_PolicyCounterTimer (TPM_CC)(0x0000016D)
+#define TPM_CC_PolicyCpHash (TPM_CC)(0x0000016E)
+#define TPM_CC_PolicyLocality (TPM_CC)(0x0000016F)
+#define TPM_CC_PolicyNameHash (TPM_CC)(0x00000170)
+#define TPM_CC_PolicyOR (TPM_CC)(0x00000171)
+#define TPM_CC_PolicyTicket (TPM_CC)(0x00000172)
+#define TPM_CC_ReadPublic (TPM_CC)(0x00000173)
+#define TPM_CC_RSAEP (TPM_CC)(0x00000174)
+#define TPM_CC_RSAES_OAEP_Encrypt (TPM_CC)(0x00000175)
+#define TPM_CC_StartAuthSession (TPM_CC)(0x00000176)
+#define TPM_CC_VerifySignature (TPM_CC)(0x00000177)
+#define TPM_CC_ECC_Parameters (TPM_CC)(0x00000178)
+#define TPM_CC_FirmwareRead (TPM_CC)(0x00000179)
+#define TPM_CC_GetCapability (TPM_CC)(0x0000017A)
+#define TPM_CC_GetRandom (TPM_CC)(0x0000017B)
+#define TPM_CC_GetTestResult (TPM_CC)(0x0000017C)
+#define TPM_CC_Hash (TPM_CC)(0x0000017D)
+#define TPM_CC_PCR_Read (TPM_CC)(0x0000017E)
+#define TPM_CC_PolicyPCR (TPM_CC)(0x0000017F)
+#define TPM_CC_PolicyRestart (TPM_CC)(0x00000180)
+#define TPM_CC_ReadClock (TPM_CC)(0x00000181)
+#define TPM_CC_PCR_Extend (TPM_CC)(0x00000182)
+#define TPM_CC_PCR_SetAuthValue (TPM_CC)(0x00000183)
+#define TPM_CC_NV_Certify (TPM_CC)(0x00000184)
+#define TPM_CC_EventSequenceComplete (TPM_CC)(0x00000185)
+#define TPM_CC_HashSequenceStart (TPM_CC)(0x00000186)
+#define TPM_CC_PolicyPhysicalPresence (TPM_CC)(0x00000187)
+#define TPM_CC_PolicyDuplicationSelect (TPM_CC)(0x00000188)
+#define TPM_CC_PolicyGetDigest (TPM_CC)(0x00000189)
+#define TPM_CC_TestParms (TPM_CC)(0x0000018A)
+#define TPM_CC_ECDAA_Certify (TPM_CC)(0x0000018B)
+#define TPM_CC_PolicyPassword (TPM_CC)(0x0000018C)
+#define TPM_CC_LAST (TPM_CC)(0x0000018C)
+
+
+
+
+// Table 11 -- TPM_RC from outputConstDef <O,S>
+typedef UINT32 TPM_RC;
+
+#define TPM_RC_SUCCESS (TPM_RC)(0x000)
+#define TPM_RC_BAD_TAG (TPM_RC)(0x030)
+#define RC_VER1 (TPM_RC)(0x100)
+#define TPM_RC_PRIVATE (TPM_RC)(RC_VER1 + 0x00B)
+#define TPM_RC_INITIALIZE (TPM_RC)(RC_VER1 + 0x000)
+#define TPM_RC_FAILURE (TPM_RC)(RC_VER1 + 0x001)
+#define TPM_RC_SEQUENCE (TPM_RC)(RC_VER1 + 0x003)
+#define TPM_RC_HMAC (TPM_RC)(RC_VER1 + 0x019)
+#define TPM_RC_DISABLED (TPM_RC)(RC_VER1 + 0x020)
+#define TPM_RC_EXCLUSIVE (TPM_RC)(RC_VER1 + 0x021)
+#define TPM_RC_ECC_CURVE (TPM_RC)(RC_VER1 + 0x023)
+#define TPM_RC_AUTH_TYPE (TPM_RC)(RC_VER1 + 0x024)
+#define TPM_RC_AUTH_MISSING (TPM_RC)(RC_VER1 + 0x025)
+#define TPM_RC_POLICY (TPM_RC)(RC_VER1 + 0x026)
+#define TPM_RC_PCR (TPM_RC)(RC_VER1 + 0x027)
+#define TPM_RC_PCR_CHANGED (TPM_RC)(RC_VER1 + 0x028)
+#define TPM_RC_ECC_POINT (TPM_RC)(RC_VER1 + 0x02C)
+#define TPM_RC_UPGRADE (TPM_RC)(RC_VER1 + 0x02D)
+#define TPM_RC_TOO_MANY_CONTEXTS (TPM_RC)(RC_VER1 + 0x02E)
+#define TPM_RC_AUTH_UNAVAILABLE (TPM_RC)(RC_VER1 + 0x02F)
+#define TPM_RC_REBOOT (TPM_RC)(RC_VER1 + 0x030)
+#define TPM_RC_COMMAND_SIZE (TPM_RC)(RC_VER1 + 0x042)
+#define TPM_RC_COMMAND_CODE (TPM_RC)(RC_VER1 + 0x043)
+#define TPM_RC_AUTHSIZE (TPM_RC)(RC_VER1 + 0x044)
+#define TPM_RC_AUTH_CONTEXT (TPM_RC)(RC_VER1 + 0x045)
+#define TPM_RC_NV_RANGE (TPM_RC)(RC_VER1 + 0x046)
+#define TPM_RC_NV_SIZE (TPM_RC)(RC_VER1 + 0x047)
+#define TPM_RC_NV_LOCKED (TPM_RC)(RC_VER1 + 0x048)
+#define TPM_RC_NV_AUTHORIZATION (TPM_RC)(RC_VER1 + 0x049)
+#define TPM_RC_NV_UNINITIALIZED (TPM_RC)(RC_VER1 + 0x04A)
+#define TPM_RC_NV_SPACE (TPM_RC)(RC_VER1 + 0x04B)
+#define TPM_RC_NV_DEFINED (TPM_RC)(RC_VER1 + 0x04C)
+#define TPM_RC_BAD_CONTEXT (TPM_RC)(RC_VER1 + 0x050)
+#define TPM_RC_CPHASH (TPM_RC)(RC_VER1 + 0x051)
+#define TPM_RC_PARENT (TPM_RC)(RC_VER1 + 0x052)
+#define RC_MAX_FM0 (TPM_RC)(RC_VER1 + 0x07F)
+#define RC_FMT1 (TPM_RC)(0x080)
+#define TPM_RC_ASYMMETRIC (TPM_RC)(RC_FMT1 + 0x001)
+#define TPM_RC_ATTRIBUTES (TPM_RC)(RC_FMT1 + 0x002)
+#define TPM_RC_HASH (TPM_RC)(RC_FMT1 + 0x003)
+#define TPM_RC_VALUE (TPM_RC)(RC_FMT1 + 0x004)
+#define TPM_RC_HIERARCHY (TPM_RC)(RC_FMT1 + 0x005)
+#define TPM_RC_KEY_SIZE (TPM_RC)(RC_FMT1 + 0x007)
+#define TPM_RC_MGF (TPM_RC)(RC_FMT1 + 0x008)
+#define TPM_RC_MODE (TPM_RC)(RC_FMT1 + 0x009)
+#define TPM_RC_TYPE (TPM_RC)(RC_FMT1 + 0x00A)
+#define TPM_RC_HANDLE (TPM_RC)(RC_FMT1 + 0x00B)
+#define TPM_RC_KDF (TPM_RC)(RC_FMT1 + 0x00C)
+#define TPM_RC_RANGE (TPM_RC)(RC_FMT1 + 0x00D)
+#define TPM_RC_AUTH_FAIL (TPM_RC)(RC_FMT1 + 0x00E)
+#define TPM_RC_NONCE (TPM_RC)(RC_FMT1 + 0x00F)
+#define TPM_RC_PP (TPM_RC)(RC_FMT1 + 0x010)
+#define TPM_RC_SCHEME (TPM_RC)(RC_FMT1 + 0x012)
+#define TPM_RC_SIZE (TPM_RC)(RC_FMT1 + 0x015)
+#define TPM_RC_SYMMETRIC (TPM_RC)(RC_FMT1 + 0x016)
+#define TPM_RC_TAG (TPM_RC)(RC_FMT1 + 0x017)
+#define TPM_RC_SELECTOR (TPM_RC)(RC_FMT1 + 0x018)
+#define TPM_RC_INSUFFICIENT (TPM_RC)(RC_FMT1 + 0x01A)
+#define TPM_RC_SIGNATURE (TPM_RC)(RC_FMT1 + 0x01B)
+#define TPM_RC_KEY (TPM_RC)(RC_FMT1 + 0x01C)
+#define TPM_RC_POLICY_FAIL (TPM_RC)(RC_FMT1 + 0x01D)
+#define TPM_RC_INTEGRITY (TPM_RC)(RC_FMT1 + 0x01F)
+#define TPM_RC_TICKET (TPM_RC)(RC_FMT1 + 0x020)
+#define TPM_RC_RESERVED_BITS (TPM_RC)(RC_FMT1 + 0x021)
+#define RC_WARN (TPM_RC)(0x900)
+#define TPM_RC_CONTEXT_GAP (TPM_RC)(RC_WARN + 0x001)
+#define TPM_RC_OBJECT_MEMORY (TPM_RC)(RC_WARN + 0x002)
+#define TPM_RC_SESSION_MEMORY (TPM_RC)(RC_WARN + 0x003)
+#define TPM_RC_MEMORY (TPM_RC)(RC_WARN + 0x004)
+#define TPM_RC_SESSION_HANDLES (TPM_RC)(RC_WARN + 0x005)
+#define TPM_RC_OBJECT_HANDLES (TPM_RC)(RC_WARN + 0x006)
+#define TPM_RC_LOCALITY (TPM_RC)(RC_WARN + 0x007)
+#define TPM_RC_YIELDED (TPM_RC)(RC_WARN + 0x008)
+#define TPM_RC_CANCELLED (TPM_RC)(RC_WARN + 0x009)
+#define TPM_RC_TESTING (TPM_RC)(RC_WARN + 0x00A)
+#define TPM_RC_REFERENCE_H0 (TPM_RC)(RC_WARN + 0x010)
+#define TPM_RC_REFERENCE_H1 (TPM_RC)(RC_WARN + 0x011)
+#define TPM_RC_REFERENCE_H2 (TPM_RC)(RC_WARN + 0x012)
+#define TPM_RC_REFERENCE_H3 (TPM_RC)(RC_WARN + 0x013)
+#define TPM_RC_REFERENCE_H4 (TPM_RC)(RC_WARN + 0x014)
+#define TPM_RC_REFERENCE_H5 (TPM_RC)(RC_WARN + 0x015)
+#define TPM_RC_REFERENCE_H6 (TPM_RC)(RC_WARN + 0x016)
+#define TPM_RC_REFERENCE_S0 (TPM_RC)(RC_WARN + 0x018)
+#define TPM_RC_REFERENCE_S1 (TPM_RC)(RC_WARN + 0x019)
+#define TPM_RC_REFERENCE_S2 (TPM_RC)(RC_WARN + 0x01A)
+#define TPM_RC_REFERENCE_S3 (TPM_RC)(RC_WARN + 0x01B)
+#define TPM_RC_REFERENCE_S4 (TPM_RC)(RC_WARN + 0x01C)
+#define TPM_RC_REFERENCE_S5 (TPM_RC)(RC_WARN + 0x01D)
+#define TPM_RC_REFERENCE_S6 (TPM_RC)(RC_WARN + 0x01E)
+#define TPM_RC_REFERENCE_S7 (TPM_RC)(RC_WARN + 0x01F)
+#define TPM_RC_NV_RATE (TPM_RC)(RC_WARN + 0x020)
+#define TPM_RC_LOCKOUT (TPM_RC)(RC_WARN + 0x021)
+#define TPM_RC_H (TPM_RC)(0x000)
+#define TPM_RC_P (TPM_RC)(0x040)
+#define TPM_RC_S (TPM_RC)(0x800)
+#define TPM_RC_1 (TPM_RC)(0x100)
+#define TPM_RC_2 (TPM_RC)(0x200)
+#define TPM_RC_3 (TPM_RC)(0x300)
+#define TPM_RC_4 (TPM_RC)(0x400)
+#define TPM_RC_5 (TPM_RC)(0x500)
+#define TPM_RC_6 (TPM_RC)(0x600)
+#define TPM_RC_7 (TPM_RC)(0x700)
+#define TPM_RC_8 (TPM_RC)(0x800)
+#define TPM_RC_9 (TPM_RC)(0x900)
+#define TPM_RC_A (TPM_RC)(0xA00)
+#define TPM_RC_B (TPM_RC)(0xB00)
+#define TPM_RC_C (TPM_RC)(0xC00)
+#define TPM_RC_D (TPM_RC)(0xD00)
+#define TPM_RC_E (TPM_RC)(0xE00)
+#define TPM_RC_F (TPM_RC)(0xF00)
+#define TPM_RC_N_MASK (TPM_RC)(0xF00)
+
+
+
+
+// Table 12 -- TPM_CLOCK_ADJUST from outputConstDef <I,S>
+typedef INT8 TPM_CLOCK_ADJUST;
+
+#define TPM_CLOCK_COARSE_SLOWER (TPM_CLOCK_ADJUST)(-3)
+#define TPM_CLOCK_MEDIUM_SLOWER (TPM_CLOCK_ADJUST)(-2)
+#define TPM_CLOCK_FINE_SLOWER (TPM_CLOCK_ADJUST)(-1)
+#define TPM_CLOCK_NO_CHANGE (TPM_CLOCK_ADJUST)(0)
+#define TPM_CLOCK_FINE_FASTER (TPM_CLOCK_ADJUST)(1)
+#define TPM_CLOCK_MEDIUM_FASTER (TPM_CLOCK_ADJUST)(2)
+#define TPM_CLOCK_COARSE_FASTER (TPM_CLOCK_ADJUST)(3)
+
+
+
+
+// Table 13 -- TPM_EO from outputConstDef <I/O,S>
+typedef UINT16 TPM_EO;
+
+#define TPM_EO_EQ (TPM_EO)(0x0000)
+#define TPM_EO_NEQ (TPM_EO)(0x0001)
+#define TPM_EO_SIGNED_GT (TPM_EO)(0x0002)
+#define TPM_EO_UNSIGNED_GT (TPM_EO)(0x0003)
+#define TPM_EO_SIGNED_LT (TPM_EO)(0x0004)
+#define TPM_EO_UNSIGNED_LT (TPM_EO)(0x0005)
+#define TPM_EO_SIGNED_GE (TPM_EO)(0x0006)
+#define TPM_EO_UNSIGNED_GE (TPM_EO)(0x0007)
+#define TPM_EO_SIGNED_LE (TPM_EO)(0x0008)
+#define TPM_EO_UNSIGNED_LE (TPM_EO)(0x0009)
+#define TPM_EO_BITSET (TPM_EO)(0x000A)
+#define TPM_EO_BITCLEAR (TPM_EO)(0x000B)
+
+
+
+
+// Table 14 -- TPM_ST from outputConstDef <I/O,S>
+typedef UINT16 TPM_ST;
+
+#define TPM_ST_RSP_COMMAND (TPM_ST)(0x00C4)
+#define TPM_ST_NULL (TPM_ST)(0X8000)
+#define TPM_ST_NO_SESSIONS (TPM_ST)(0x8001)
+#define TPM_ST_SESSIONS (TPM_ST)(0x8002)
+#define TPM_ST_ATTEST_COMMAND_AUDIT (TPM_ST)(0x8015)
+#define TPM_ST_ATTEST_SESSION_AUDIT (TPM_ST)(0x8016)
+#define TPM_ST_ATTEST_CERTIFY (TPM_ST)(0x8017)
+#define TPM_ST_ATTEST_QUOTE (TPM_ST)(0x8018)
+#define TPM_ST_ATTEST_TIME (TPM_ST)(0x8019)
+#define TPM_ST_ATTEST_CREATION (TPM_ST)(0x801A)
+#define TPM_ST_ATTEST_NV (TPM_ST)(0x801B)
+#define TPM_ST_CREATION (TPM_ST)(0x8021)
+#define TPM_ST_VERIFIED (TPM_ST)(0x8022)
+#define TPM_ST_AUTH (TPM_ST)(0x8023)
+#define TPM_ST_HASHCHECK (TPM_ST)(0x8024)
+#define TPM_ST_FU_MANIFEST (TPM_ST)(0x8029)
+
+
+// Table 15 -- TPM_SU from outputConstDef <I>
+typedef UINT16 TPM_SU;
+
+#define TPM_SU_CLEAR (TPM_SU)(0x0000)
+#define TPM_SU_STATE (TPM_SU)(0x0001)
+
+
+
+
+// Table 16 -- TPM_SE from outputConstDef <I>
+typedef UINT8 TPM_SE;
+
+#define TPM_SE_HMAC (TPM_SE)(0x00)
+#define TPM_SE_POLICY (TPM_SE)(0x01)
+#define TPM_SE_TRIAL (TPM_SE)(0x03)
+
+
+
+
+// Table 17 -- TPM_CAP from outputConstDef <I/O,S>
+typedef UINT32 TPM_CAP;
+
+#define TPM_CAP_FIRST (TPM_CAP)(0x00000000)
+#define TPM_CAP_ALGS (TPM_CAP)(0x00000000)
+#define TPM_CAP_HANDLES (TPM_CAP)(0x00000001)
+#define TPM_CAP_COMMANDS (TPM_CAP)(0x00000002)
+#define TPM_CAP_PP_COMMANDS (TPM_CAP)(0x00000003)
+#define TPM_CAP_AUDIT_COMMANDS (TPM_CAP)(0x00000004)
+#define TPM_CAP_PCRS (TPM_CAP)(0x00000005)
+#define TPM_CAP_TPM_PROPERTIES (TPM_CAP)(0x00000006)
+#define TPM_CAP_PCR_PROPERTIES (TPM_CAP)(0x00000007)
+#define TPM_CAP_ECC_CURVES (TPM_CAP)(0x00000008)
+#define TPM_CAP_LAST (TPM_CAP)(0x00000008)
+#define TPM_CAP_VENDOR_PROPERTY (TPM_CAP)(0x00000100)
+
+
+
+
+// Table 18 -- TPM_PT from outputConstDef <I/O,S>
+typedef UINT32 TPM_PT;
+
+#define TPM_PT_NONE (TPM_PT)(0x00000000)
+#define PT_GROUP (TPM_PT)(0x00000100)
+#define PT_FIXED (TPM_PT)(PT_GROUP * 1)
+#define TPM_PT_FAMILY_INDICATOR (TPM_PT)(PT_FIXED + 0)
+#define TPM_PT_LEVEL (TPM_PT)(PT_FIXED + 1)
+#define TPM_PT_REVISION (TPM_PT)(PT_FIXED + 2)
+#define TPM_PT_DAY_OF_YEAR (TPM_PT)(PT_FIXED + 3)
+#define TPM_PT_YEAR (TPM_PT)(PT_FIXED + 4)
+#define TPM_PT_MANUFACTURER (TPM_PT)(PT_FIXED + 5)
+#define TPM_PT_VENDOR_TPM_TYPE (TPM_PT)(PT_FIXED + 6)
+#define TPM_PT_FIRMWARE_VERSION_1 (TPM_PT)(PT_FIXED + 7)
+#define TPM_PT_FIRMWARE_VERSION_2 (TPM_PT)(PT_FIXED + 8)
+#define TPM_PT_INPUT_BUFFER (TPM_PT)(PT_FIXED + 9)
+#define TPM_PT_HR_TRANSIENT_MIN (TPM_PT)(PT_FIXED + 10)
+#define TPM_PT_HR_PERSISTENT_MIN (TPM_PT)(PT_FIXED + 11)
+#define TPM_PT_HR_LOADED_MIN (TPM_PT)(PT_FIXED + 12)
+#define TPM_PT_ACTIVE_SESSIONS_MAX (TPM_PT)(PT_FIXED + 13)
+#define TPM_PT_PCR_COUNT (TPM_PT)(PT_FIXED + 14)
+#define TPM_PT_PCR_SELECT_MIN (TPM_PT)(PT_FIXED + 15)
+#define TPM_PT_CONTEXT_GAP_MAX (TPM_PT)(PT_FIXED + 16)
+#define TPM_PT_NV_COUNTERS_MAX (TPM_PT)(PT_FIXED + 17)
+#define TPM_PT_NV_INDEX_MAX (TPM_PT)(PT_FIXED + 18)
+#define TPM_PT_MEMORY (TPM_PT)(PT_FIXED + 19)
+#define TPM_PT_CLOCK_UPDATE (TPM_PT)(PT_FIXED + 20)
+#define TPM_PT_CONTEXT_HASH (TPM_PT)(PT_FIXED + 22)
+#define TPM_PT_CONTEXT_SYM (TPM_PT)(PT_FIXED + 23)
+#define TPM_PT_CONTEXT_SYM_SIZE (TPM_PT)(PT_FIXED + 24)
+#define TPM_PT_ORDERLY_COUNT (TPM_PT)(PT_FIXED + 25)
+#define TPM_PT_MAX_COMMAND_SIZE (TPM_PT)(PT_FIXED + 26)
+#define TPM_PT_MAX_RESPONSE_SIZE (TPM_PT)(PT_FIXED + 27)
+#define TPM_PT_MAX_DIGEST (TPM_PT)(PT_FIXED + 28)
+#define TPM_PT_MAX_OBJECT_CONTEXT (TPM_PT)(PT_FIXED + 29)
+#define TPM_PT_MAX_SESSION_CONTEXT (TPM_PT)(PT_FIXED+ 30)
+#define PT_VAR (TPM_PT)(PT_GROUP * 2)
+#define TPM_PT_PERMANENT (TPM_PT)(PT_VAR + 0)
+#define TPM_PT_STARTUP_CLEAR (TPM_PT)(PT_VAR + 1)
+#define TPM_PT_HR_NV_INDEX (TPM_PT)(PT_VAR + 2)
+#define TPM_PT_HR_LOADED (TPM_PT)(PT_VAR + 3)
+#define TPM_PT_HR_LOADED_AVAIL (TPM_PT)(PT_VAR + 4)
+#define TPM_PT_HR_ACTIVE (TPM_PT)(PT_VAR + 5)
+#define TPM_PT_HR_ACTIVE_AVAIL (TPM_PT)(PT_VAR + 6)
+#define TPM_PT_HR_TRANSIENT_AVAIL (TPM_PT)(PT_VAR + 7)
+#define TPM_PT_HR_PERSISTENT (TPM_PT)(PT_VAR + 8)
+#define TPM_PT_HR_PERSISTENT_AVAIL (TPM_PT)(PT_VAR + 9)
+#define TPM_PT_NV_COUNTERS (TPM_PT)(PT_VAR + 10)
+#define TPM_PT_NV_COUNTERS_AVAIL (TPM_PT)(PT_VAR + 11)
+#define TPM_PT_REGION (TPM_PT)(PT_VAR + 12)
+#define TPM_PT_LOADED_CURVES (TPM_PT)(PT_VAR + 13)
+#define TPM_PT_AUDIT_COUNTER (TPM_PT)(PT_VAR + 14)
+#define TPM_PT_LOCKOUT_COUNTER (TPM_PT)(PT_VAR + 15)
+#define TPM_PT_MAX_AUTH_FAIL (TPM_PT)(PT_VAR + 16)
+#define TPM_PT_LOCKOUT_INTERVAL (TPM_PT)(PT_VAR + 17)
+#define TPM_PT_LOCKOUT_RECOVERY (TPM_PT)(PT_VAR + 18)
+#define TPM_PT_NV_WRITE_RECOVERY (TPM_PT)(PT_VAR + 19)
+
+
+// Table 19 -- TPM_PT_PCR from outputConstDef <I/O,S>
+typedef UINT32 TPM_PT_PCR;
+
+#define TPM_PT_PCR_FIRST (TPM_PT_PCR)(0x00000000)
+#define TPM_PT_PCR_SAVE (TPM_PT_PCR)(0x00000000)
+#define TPM_PT_PCR_EXTEND_L0 (TPM_PT_PCR)(0x00000001)
+#define TPM_PT_PCR_RESET_L0 (TPM_PT_PCR)(0x00000002)
+#define TPM_PT_PCR_EXTEND_L1 (TPM_PT_PCR)(0x00000003)
+#define TPM_PT_PCR_RESET_L1 (TPM_PT_PCR)(0x00000004)
+#define TPM_PT_PCR_EXTEND_L2 (TPM_PT_PCR)(0x00000005)
+#define TPM_PT_PCR_RESET_L2 (TPM_PT_PCR)(0x00000006)
+#define TPM_PT_PCR_EXTEND_L3 (TPM_PT_PCR)(0x00000007)
+#define TPM_PT_PCR_RESET_L3 (TPM_PT_PCR)(0x00000008)
+#define TPM_PT_PCR_EXTEND_L4 (TPM_PT_PCR)(0x00000009)
+#define TPM_PT_PCR_RESET_L4 (TPM_PT_PCR)(0x0000000A)
+#define TPM_PT_PCR_DRTM_RESET (TPM_PT_PCR)(0x0000000B)
+#define TPM_PT_PCR_POLICY (TPM_PT_PCR)(0x0000000C)
+#define TPM_PT_PCR_AUTH (TPM_PT_PCR)(0x0000000D)
+#define TPM_PT_PCR_LAST (TPM_PT_PCR)(0x0000000D)
+
+
+// Table 20 -- Handles from outputTypeDef <I/O>
+typedef UINT32 TPM_HANDLE;
+
+// Table 21 -- TPM_HT from outputConstDef <S>
+typedef UINT8 TPM_HT;
+
+#define TPM_HT_PCR (TPM_HT)(0x00)
+#define TPM_HT_NV_INDEX (TPM_HT)(0x01)
+#define TPM_HT_HMAC_SESSION (TPM_HT)(0x02)
+#define TPM_HT_LOADED_SESSION (TPM_HT)(0x02)
+#define TPM_HT_POLICY_SESSION (TPM_HT)(0x03)
+#define TPM_HT_ACTIVE_SESSION (TPM_HT)(0x03)
+#define TPM_HT_PERMANENT (TPM_HT)(0x40)
+#define TPM_HT_TRANSIENT (TPM_HT)(0x80)
+#define TPM_HT_PERSISTENT (TPM_HT)(0x81)
+
+
+
+
+// Table 22 -- TPM_RH from outputConstDef <I,S>
+typedef UINT32 TPM_RH;
+
+#define TPM_RH_FIRST (TPM_RH)(0x40000000)
+#define TPM_RH_SRK (TPM_RH)(0x40000000)
+#define TPM_RH_OWNER (TPM_RH)(0x40000001)
+#define TPM_RH_REVOKE (TPM_RH)(0x40000002)
+#define TPM_RH_TRANSPORT (TPM_RH)(0x40000003)
+#define TPM_RH_OPERATOR (TPM_RH)(0x40000004)
+#define TPM_RH_ADMIN (TPM_RH)(0x40000005)
+#define TPM_RH_EK (TPM_RH)(0x40000006)
+#define TPM_RH_NULL (TPM_RH)(0x40000007)
+#define TPM_RH_UNASSIGNED (TPM_RH)(0x40000008)
+#define TPM_RH_PW (TPM_RH)(0x40000009)
+#define TPM_RS_PW (TPM_RH)(0x40000009)
+#define TPM_RH_LOCKOUT (TPM_RH)(0x4000000A)
+#define TPM_RH_ENDORSEMENT (TPM_RH)(0x4000000B)
+#define TPM_RH_PLATFORM (TPM_RH)(0x4000000C)
+#define TPM_RH_LAST (TPM_RH)(0x4000000C)
+#define TPM_RH_PCR0 (TPM_RH)(0x00000000)
+
+
+// Table 23 -- TPM_HC from outputConstDef <I,S>
+typedef TPM_HANDLE TPM_HC;
+
+#define HR_HANDLE_MASK (TPM_HC)(0x00FFFFFF)
+#define HR_RANGE_MASK (TPM_HC)(0xFF000000)
+#define HR_SHIFT (TPM_HC)(24)
+#define HR_PCR (TPM_HC)(TPM_HT_PCR << HR_SHIFT)
+#define HR_HMAC_SESSION (TPM_HC)(TPM_HT_HMAC_SESSION << HR_SHIFT)
+#define HR_POLICY_SESSION (TPM_HC)(TPM_HT_POLICY_SESSION << HR_SHIFT)
+#define HR_TRANSIENT (TPM_HC)(TPM_HT_TRANSIENT << HR_SHIFT)
+#define HR_PERSISTENT (TPM_HC)(TPM_HT_PERSISTENT << HR_SHIFT)
+#define HR_NV_INDEX (TPM_HC)(TPM_HT_NV_INDEX << HR_SHIFT)
+#define HR_PERMANENT (TPM_HC)(TPM_HT_PERMANENT << HR_SHIFT)
+#define PCR_FIRST (TPM_HC)(TPM_RH_PCR0)
+#define PCR_LAST (TPM_HC)(PCR_FIRST + IMPLEMENTATION_PCR-1)
+#define HMAC_SESSION_FIRST (TPM_HC)(HR_HMAC_SESSION + 0)
+#define HMAC_SESSION_LAST (TPM_HC)(HMAC_SESSION_FIRST+MAX_ACTIVE_SESSIONS-1)
+#define POLICY_SESSION_FIRST (TPM_HC)(HR_POLICY_SESSION + 0)
+#define POLICY_SESSION_LAST (TPM_HC)(POLICY_SESSION_FIRST + MAX_ACTIVE_SESSIONS-1)
+#define TRANSIENT_FIRST (TPM_HC)(HR_TRANSIENT + 0)
+#define TRANSIENT_LAST (TPM_HC)(TRANSIENT_FIRST+MAX_LOADED_OBJECTS-1)
+#define PERSISTENT_FIRST (TPM_HC)(HR_PERSISTENT + 0)
+#define PERSISTENT_LAST (TPM_HC)(PERSISTENT_FIRST + 0x00FFFFFF)
+#define PLATFORM_PERSISTENT (TPM_HC)(PERSISTENT_FIRST + 0x00800000)
+#define NV_INDEX_FIRST (TPM_HC)(HR_NV_INDEX + 0)
+#define NV_INDEX_LAST (TPM_HC)(NV_INDEX_FIRST + 0x00FFFFFF)
+#define PERMANENT_FIRST (TPM_HC)(TPM_RH_FIRST)
+#define PERMANENT_LAST (TPM_HC)(TPM_RH_LAST)
+
+
+// Table 24 -- TPMA_ALGORITHM from outputBitDef <I/O>
+typedef struct {
+ unsigned int asymmetric : 1;
+ unsigned int symmetric : 1;
+ unsigned int hash : 1;
+ unsigned int reserved4 : 5;
+ unsigned int signing : 1;
+ unsigned int encrypting : 1;
+ unsigned int method : 1;
+ unsigned int reserved8 : 21;
+} TPMA_ALGORITHM ;
+
+// Table 25 -- TPMA_OBJECT from outputBitDef <I/O>
+typedef struct {
+ unsigned int reserved1 : 1;
+ unsigned int fixedTPM : 1;
+ unsigned int stClear : 1;
+ unsigned int reserved4 : 1;
+ unsigned int fixedParent : 1;
+ unsigned int newKey : 1;
+ unsigned int withAuth : 1;
+ unsigned int withPolicy : 1;
+ unsigned int Pad9 : 1; //Inserted extra pad
+ unsigned int fixedEmptyAuth : 1;
+ unsigned int noDA : 1;
+ unsigned int reserved11 : 5;
+ unsigned int restricted : 1;
+ unsigned int decrypt : 1;
+ unsigned int sign : 1;
+ unsigned int Pad15 : 13;
+} TPMA_OBJECT ;
+
+// Table 26 -- TPMA_SESSION from outputBitDef <I/O>
+typedef struct {
+ unsigned int continueSession : 1;
+ unsigned int auditExclusive : 1;
+ unsigned int auditReset : 1;
+ unsigned int reserved4 : 2;
+ unsigned int encrypted : 1;
+ unsigned int encrypt : 1;
+ unsigned int audit : 1;
+} TPMA_SESSION ;
+
+// Table 27 -- TPMA_LOCALITY from outputBitDef <I/O>
+typedef struct {
+ unsigned int TPM2_LOC_ZERO : 1;
+ unsigned int TPM2_LOC_ONE : 1;
+ unsigned int TPM2_LOC_TWO : 1;
+ unsigned int TPM2_LOC_THREE : 1;
+ unsigned int TPM2_LOC_FOUR : 1;
+ unsigned int reserved6 : 3;
+} TPMA_LOCALITY ;
+
+// Table 28 -- TPMA_PERMANENT from outputBitDef <O,S>
+typedef struct {
+ unsigned int ownerAuthSet : 1;
+ unsigned int endorsementAuthSet : 1;
+ unsigned int lockoutAuthSet : 1;
+ unsigned int reserved4 : 5;
+ unsigned int disableClear : 1;
+ unsigned int inLockout : 1;
+ unsigned int tpmGeneratedEPS : 1;
+ unsigned int reserved8 : 21;
+} TPMA_PERMANENT ;
+
+// Table 29 -- TPMA_STARTUP_CLEAR from outputBitDef <O,S>
+typedef struct {
+ unsigned int phEnable : 1;
+ unsigned int shEnable : 1;
+ unsigned int ehEnable : 1;
+ unsigned int reserved4 : 28;
+ unsigned int orderly : 1;
+} TPMA_STARTUP_CLEAR ;
+
+// Table 30 -- TPMA_MEMORY from outputBitDef <O,S>
+typedef struct {
+ unsigned int sharedRAM : 1;
+ unsigned int sharedNV : 1;
+ unsigned int objectCopiedToRam : 1;
+ unsigned int reserved4 : 29;
+} TPMA_MEMORY ;
+
+// Table 31 -- TPMI_YES_NO from outputType <I/O>
+typedef BYTE TPMI_YES_NO;
+
+
+// Table 32 -- TPMI_DH_OBJECT from outputType <I/O>
+typedef TPM_HANDLE TPMI_DH_OBJECT;
+
+
+// Table 33 -- TPMI_DH_PERSISTENT from outputType <I/O>
+typedef TPM_HANDLE TPMI_DH_PERSISTENT;
+
+
+// Table 34 -- TPMI_DH_ENTITY from outputType <I>
+typedef TPM_HANDLE TPMI_DH_ENTITY;
+
+
+// Table 35 -- TPMI_DH_PARENT from outputType <I>
+typedef TPM_HANDLE TPMI_DH_PARENT;
+
+
+// Table 36 -- TPMI_DH_PCR from outputType <I>
+typedef TPM_HANDLE TPMI_DH_PCR;
+
+
+// Table 37 -- TPMI_SH_AUTH_SESSION from outputType <I/O>
+typedef TPM_HANDLE TPMI_SH_AUTH_SESSION;
+
+
+// Table 38 -- TPMI_SH_HMAC from outputType <I/O>
+typedef TPM_HANDLE TPMI_SH_HMAC;
+
+
+// Table 39 -- TPMI_SH_POLICY from outputType <I/O>
+typedef TPM_HANDLE TPMI_SH_POLICY;
+
+
+// Table 40 -- TPMI_DH_CONTEXT from outputType <I/O>
+typedef TPM_HANDLE TPMI_DH_CONTEXT;
+
+
+// Table 41 -- TPMI_RH_HIERARCHY from outputType <I/O>
+typedef TPM_HANDLE TPMI_RH_HIERARCHY;
+
+
+// Table 42 -- TPMI_RH_HIERARCHY_AUTH from outputType <I>
+typedef TPM_HANDLE TPMI_RH_HIERARCHY_AUTH;
+
+
+// Table 43 -- TPMI_RH_PLATFORM from outputType <I>
+typedef TPM_HANDLE TPMI_RH_PLATFORM;
+
+
+// Table 44 -- TPMI_RH_OWNER from outputType <I>
+typedef TPM_HANDLE TPMI_RH_OWNER;
+
+
+// Table 45 -- TPMI_RH_ENDORSEMENT from outputType <I>
+typedef TPM_HANDLE TPMI_RH_ENDORSEMENT;
+
+
+// Table 46 -- TPMI_RH_PROVISION from outputType <I>
+typedef TPM_HANDLE TPMI_RH_PROVISION;
+
+
+// Table 47 -- TPMI_RH_CLEAR from outputType <I>
+typedef TPM_HANDLE TPMI_RH_CLEAR;
+
+
+// Table 48 -- TPMI_RH_NV_AUTH from outputType <I>
+typedef TPM_HANDLE TPMI_RH_NV_AUTH;
+
+
+// Table 49 -- TPMI_RH_LOCKOUT from outputType <I>
+typedef TPM_HANDLE TPMI_RH_LOCKOUT;
+
+
+// Table 50 -- TPMI_RH_NV_INDEX from outputType <I/O>
+typedef TPM_HANDLE TPMI_RH_NV_INDEX;
+
+
+// Table 51 -- TPMI_ALG_HASH from outputType <I/O>
+typedef TPM2_ALG_ID TPMI_ALG_HASH;
+
+
+// Table 52 -- TPMI_ALG_ASYM from outputType <I/O>
+typedef TPM2_ALG_ID TPMI_ALG_ASYM;
+
+
+// Table 53 -- TPMI_ALG_SYM from outputType <I/O>
+typedef TPM2_ALG_ID TPMI_ALG_SYM;
+
+
+// Table 54 -- TPMI_ALG_SYM_OBJECT from outputType <I/O>
+typedef TPM2_ALG_ID TPMI_ALG_SYM_OBJECT;
+
+
+// Table 55 -- TPMI_ALG_SYM_MODE from outputType <I/O>
+typedef TPM2_ALG_ID TPMI_ALG_SYM_MODE;
+
+
+// Table 56 -- TPMI_ALG_KDF from outputType <I/O>
+typedef TPM2_ALG_ID TPMI_ALG_KDF;
+
+
+// Table 57 -- TPMI_ALG_SIG_SCHEME from outputType <I/O>
+typedef TPM2_ALG_ID TPMI_ALG_SIG_SCHEME;
+
+
+// Table 58 -- TPMI_ST_COMMAND_TAG from outputType <I/O>
+typedef TPM_ST TPMI_ST_COMMAND_TAG;
+
+
+// Table 59 -- TPMS_ALGORITHM_DESCRIPTION from outputStructDef <O,S>
+typedef struct {
+ TPM2_ALG_ID alg;
+ TPMA_ALGORITHM attributes;
+} TPMS_ALGORITHM_DESCRIPTION;
+
+// Table 60 -- TPMU_HA from outputUnionDef <I/O,S>
+typedef union {
+#if SHA1 == YES
+ BYTE sha1[SHA1_DIGEST_SIZE];
+#endif
+#if SHA256 == YES
+ BYTE sha256[SHA256_DIGEST_SIZE];
+#endif
+#if SM3_256 == YES
+ BYTE sm3_256[SM3_256_DIGEST_SIZE];
+#endif
+#if SHA384 == YES
+ BYTE sha384[SHA384_DIGEST_SIZE];
+#endif
+#if SHA512 == YES
+ BYTE sha512[SHA512_DIGEST_SIZE];
+#endif
+#if WHIRLPOOL512 == YES
+ BYTE whirlpool[WHIRLPOOL512_DIGEST_SIZE];
+#endif
+
+} TPMU_HA ;
+
+
+// Table 61 -- TPMT_HA from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+ TPMU_HA digest;
+} TPMT_HA;
+
+// Table 62 -- TPMS_HASH_DEF from outputStructDef <O,S>
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+ UINT32 digestSize;
+ UINT32 blockSize;
+} TPMS_HASH_DEF;
+
+// Table 63 -- TPM2B_DIGEST from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE buffer[sizeof(TPMU_HA)];
+} TPM2B_DIGEST;
+
+// Table 64 -- TPM2B_DATA from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE buffer[sizeof(TPMT_HA)];
+} TPM2B_DATA;
+
+// Table 65 -- TPM2B_NONCE from outputTypeDef <I/O>
+typedef TPM2B_DIGEST TPM2B_NONCE;
+
+// Table 66 -- TPM2B_AUTH from outputTypeDef <I/O>
+typedef TPM2B_DIGEST TPM2B_AUTH;
+
+// Table 67 -- TPM2B_OPERAND from outputTypeDef <I/O>
+typedef TPM2B_DIGEST TPM2B_OPERAND;
+
+// Table 68 -- TPM2B_EVENT from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE buffer[1024];
+} TPM2B_EVENT;
+
+// Table 69 -- TPM2B_MAX_BUFFER from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE buffer[MAX_DIGEST_BUFFER];
+} TPM2B_MAX_BUFFER;
+
+// Table 70 -- TPM2B_TIMEOUT from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE buffer[sizeof(UINT64)];
+} TPM2B_TIMEOUT;
+
+// Table 71 -- TPMU_NAME from outputUnionDef <S>
+typedef union {
+ TPMU_HA digest;
+ TPM_HANDLE handle;
+
+} TPMU_NAME ;
+
+
+// Table 72 -- TPM2B_NAME from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE name[sizeof(TPMU_NAME)];
+} TPM2B_NAME;
+
+// Table 73 -- TPMS_PCR_SELECT from outputStructDef <I/O>
+typedef struct {
+ UINT8 sizeofSelect;
+ BYTE pcrSelect[PCR_SELECT_MAX];
+} TPMS_PCR_SELECT;
+
+// Table 74 -- TPMS_PCR_SELECTION from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_HASH hash;
+ UINT8 sizeofSelect;
+ BYTE pcrSelect[PCR_SELECT_MAX];
+} TPMS_PCR_SELECTION;
+
+// Table 78 -- TPMT_TK_CREATION from outputStructDef <I/O>
+typedef struct {
+ TPM_ST tag;
+ TPMI_RH_HIERARCHY hierarchy;
+ TPM2B_DIGEST digest;
+} TPMT_TK_CREATION;
+
+// Table 79 -- TPMT_TK_VERIFIED from outputStructDef <I/O>
+typedef struct {
+ TPM_ST tag;
+ TPMI_RH_HIERARCHY hierarchy;
+ TPM2B_DIGEST digest;
+} TPMT_TK_VERIFIED;
+
+// Table 80 -- TPMT_TK_AUTH from outputStructDef <I/O>
+typedef struct {
+ TPM_ST tag;
+ TPMI_RH_HIERARCHY hierarchy;
+ TPM2B_DIGEST digest;
+} TPMT_TK_AUTH;
+
+// Table 81 -- TPMT_TK_HASHCHECK from outputStructDef <I/O>
+typedef struct {
+ TPM_ST tag;
+ TPMI_RH_HIERARCHY hierarchy;
+ TPM2B_DIGEST digest;
+} TPMT_TK_HASHCHECK;
+
+// Table 82 -- TPMS_ALG_PROPERTY from outputStructDef <O,S>
+typedef struct {
+ TPM2_ALG_ID alg;
+ TPMA_ALGORITHM algProperties;
+} TPMS_ALG_PROPERTY;
+
+// Table 83 -- TPMS_TAGGED_PROPERTY from outputStructDef <O,S>
+typedef struct {
+ TPM_PT property;
+ UINT32 value;
+} TPMS_TAGGED_PROPERTY;
+
+// Table 84 -- TPMS_TAGGED_PCR_SELECT from outputStructDef <O,S>
+typedef struct {
+ TPM_PT tag;
+ UINT8 sizeofSelect;
+ BYTE pcrSelect[PCR_SELECT_MAX];
+} TPMS_TAGGED_PCR_SELECT;
+
+// Table 85 -- TPML_CC from outputStructDef <I/O>
+typedef struct {
+ UINT32 count;
+ TPM_CC commandCodes[MAX_CAP_CC];
+} TPML_CC;
+
+// Table 86 -- TPML_ALG from outputStructDef <I/O>
+typedef struct {
+ UINT32 count;
+ TPM2_ALG_ID alorithms[MAX_ALG_LIST_SIZE];
+} TPML_ALG;
+
+// Table 87 -- TPML_HANDLE from outputStructDef <O,S>
+typedef struct {
+ UINT32 count;
+ TPM_HANDLE handle[MAX_CAP_HANDLES];
+} TPML_HANDLE;
+
+// Table 88 -- TPML_DIGEST from outputStructDef <I/O>
+typedef struct {
+ UINT32 count;
+ TPM2B_DIGEST digests[8];
+} TPML_DIGEST;
+
+// Table 89 -- TPML_DIGEST_VALUES from outputStructDef <I/O>
+typedef struct {
+ UINT32 count;
+ TPMT_HA digests[HASH_COUNT];
+} TPML_DIGEST_VALUES;
+
+// Table 90 -- TPM2B_DIGEST_VALUES from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE buffer[sizeof(TPML_DIGEST_VALUES)];
+} TPM2B_DIGEST_VALUES;
+
+// Table 91 -- TPML_PCR_SELECTION from outputStructDef <I/O>
+typedef struct {
+ UINT32 count;
+ TPMS_PCR_SELECTION pcrSelections[HASH_COUNT];
+} TPML_PCR_SELECTION;
+
+// Table 92 -- TPML_ALG_PROPERTY from outputStructDef <O,S>
+typedef struct {
+ UINT32 count;
+ TPMS_ALG_PROPERTY algProperties[MAX_CAP_ALGS];
+} TPML_ALG_PROPERTY;
+
+// Table 93 -- TPML_TAGGED_TPM_PROPERTY from outputStructDef <O,S>
+typedef struct {
+ UINT32 count;
+ TPMS_TAGGED_PROPERTY pcrProperty[MAX_TPM_PROPERTIES];
+} TPML_TAGGED_TPM_PROPERTY;
+
+// Table 94 -- TPML_TAGGED_PCR_PROPERTY from outputStructDef <O,S>
+typedef struct {
+ UINT32 count;
+ TPMS_TAGGED_PCR_SELECT pcrProperty[MAX_PCR_PROPERTIES];
+} TPML_TAGGED_PCR_PROPERTY;
+
+// Table 95 -- ECCCurve from outputTypeDef <I/O>
+#if ECC == YES
+typedef UINT16 TPM_ECC_CURVE_ID;
+#endif
+
+// Table 96 -- TPML_ECC_CURVE from outputStructDef <O,S>
+#if ECC == YES
+typedef struct {
+ UINT32 count;
+ TPM_ECC_CURVE_ID eccCurves[MAX_ECC_CURVES];
+} TPML_ECC_CURVE;
+#endif
+
+// Table 97 -- TPMU_CAPABILITIES from outputUnionDef <O,S>
+typedef union {
+ TPML_ALG_PROPERTY algorithms;
+ TPML_HANDLE handles;
+ TPML_CC command;
+ TPML_CC ppCommands;
+ TPML_CC auditCommands;
+ TPML_PCR_SELECTION assignedPCR;
+ TPML_TAGGED_TPM_PROPERTY tpmProperties;
+ TPML_TAGGED_PCR_PROPERTY pcrProperties;
+ TPML_ECC_CURVE eccCurves;
+
+} TPMU_CAPABILITIES ;
+
+
+// Table 98 -- TPMS_CAPABILITY_DATA from outputStructDef <O,S>
+typedef struct {
+ TPM_CAP capability;
+ TPMU_CAPABILITIES data;
+} TPMS_CAPABILITY_DATA;
+
+// Table 99 -- TPMS_CLOCK_INFO from outputStructDef <I/O>
+typedef struct {
+ UINT64 clock;
+ TPMI_YES_NO safe;
+ UINT32 resetCount;
+ UINT32 restartCount;
+} TPMS_CLOCK_INFO;
+
+// Table 100 -- TPMS_TIME_INFO from outputStructDef <I/O>
+typedef struct {
+ UINT64 time;
+ TPMS_CLOCK_INFO clockInfo;
+} TPMS_TIME_INFO;
+
+// Table 101 -- TPMS_TIME_ATTEST_INFO from outputStructDef <O,S>
+typedef struct {
+ TPMS_TIME_INFO time;
+ UINT64 firmwareVersion;
+} TPMS_TIME_ATTEST_INFO;
+
+// Table 102 -- TPMS_CERTIFY_INFO from outputStructDef <O,S>
+typedef struct {
+ TPM2B_NAME name;
+ TPM2B_NAME qualifiedName;
+} TPMS_CERTIFY_INFO;
+
+// Table 103 -- TPMS_QUOTE_INFO from outputStructDef <O,S>
+typedef struct {
+ TPML_PCR_SELECTION pcrSelect;
+ TPM2B_DIGEST pcrDigest;
+} TPMS_QUOTE_INFO;
+
+// Table 104 -- TPMS_COMMAND_AUDIT_INFO from outputStructDef <O,S>
+typedef struct {
+ UINT32 auditCounter;
+ TPM2_ALG_ID digestAlg;
+ TPM2B_DIGEST auditDigest;
+ TPM2B_DIGEST commandDigest;
+} TPMS_COMMAND_AUDIT_INFO;
+
+// Table 105 -- TPMS_SESSION_AUDIT_INFO from outputStructDef <O,S>
+typedef struct {
+ UINT8 exclusiveSesstion;
+ TPM2B_DIGEST sessionDigest;
+} TPMS_SESSION_AUDIT_INFO;
+
+// Table 106 -- TPMS_CREATION_INFO from outputStructDef <O,S>
+typedef struct {
+ TPM2B_NAME objectName;
+} TPMS_CREATION_INFO;
+
+// Table 107 -- TPMS_NV_CERTIFY_INFO from outputStructDef <O,S>
+typedef struct {
+ TPM2B_MAX_BUFFER nvContents;
+} TPMS_NV_CERTIFY_INFO;
+
+// Table 108 -- TPMI_ST_ATTEST from outputType <O,S>
+typedef TPM_ST TPMI_ST_ATTEST;
+
+
+// Table 109 -- TPMU_ATTEST from outputUnionDef <O,S>
+typedef union {
+ TPMS_CERTIFY_INFO certify;
+ TPMS_CREATION_INFO creation;
+ TPMS_QUOTE_INFO quote;
+ TPMS_COMMAND_AUDIT_INFO commandAudit;
+ TPMS_SESSION_AUDIT_INFO sessionAudit;
+ TPMS_TIME_ATTEST_INFO time;
+ TPMS_NV_CERTIFY_INFO nv;
+
+} TPMU_ATTEST ;
+
+
+// Table 110 -- TPMS_ATTEST from outputStructDef <O,S>
+typedef struct {
+ TPM_GENERATED magic;
+ TPMI_ST_ATTEST type;
+ TPM2B_NAME qualifiedSigner;
+ TPM2B_DATA extraData;
+ TPMS_CLOCK_INFO clockInfo;
+ UINT64 firmwareVersion;
+ TPMU_ATTEST attested;
+} TPMS_ATTEST;
+
+// Table 111 -- TPM2B_ATTEST from outputStructDef <O,S>
+typedef struct {
+ UINT16 size;
+ TPMS_ATTEST attestationData;
+} TPM2B_ATTEST;
+
+// Table 112 -- TPMS_AUTH_SESSION_COMMAND from outputStructDef <I>
+typedef struct {
+ TPMI_SH_AUTH_SESSION sessionHandle;
+ TPM2B_NONCE nonce;
+ TPMA_SESSION sessionAttributes;
+ TPM2B_AUTH auth;
+} TPMS_AUTH_SESSION_COMMAND;
+
+// Table 113 -- TPMS_AUTH_SESSION_RESPONSE from outputStructDef <I/O>
+typedef struct {
+ TPM2B_NONCE nonce;
+ TPMA_SESSION sessionAttributes;
+ TPM2B_AUTH auth;
+} TPMS_AUTH_SESSION_RESPONSE;
+
+// Table 114 -- TPMS_AUTH_COMPUTE_NOT_BOUND from outputStructDef <S>
+typedef struct {
+ TPM2B_AUTH sessionKey;
+ TPM2B_AUTH authValue;
+ TPM2B_DIGEST pHash;
+ TPM2B_NONCE nonceNewer;
+ TPM2B_NONCE nonceOlder;
+ TPMA_SESSION sessionFlags;
+} TPMS_AUTH_COMPUTE_NOT_BOUND;
+
+// Table 115 -- TPMS_AUTH_COMPUTE_BOUND from outputStructDef <S>
+typedef struct {
+ TPM2B_DIGEST sessionKey;
+ TPM2B_DIGEST pHash;
+ TPM2B_NONCE nonceNewer;
+ TPM2B_NONCE nonceOlder;
+ TPMA_SESSION sessionFlags;
+} TPMS_AUTH_COMPUTE_BOUND;
+
+// Table 116 -- TPMS_XOR_PARMS from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_HASH hash;
+} TPMS_XOR_PARMS;
+
+// Table 117 -- TPMS_AES_PARMS from outputStructDef <I/O>
+#if AES == YES
+typedef struct {
+ TPM_KEY_BITS keyBits;
+ TPMI_ALG_SYM_MODE mode;
+} TPMS_AES_PARMS;
+#endif
+
+// Table 118 -- TPMS_SMS4_PARMS from outputStructDef <I/O>
+#if SMS4 == YES
+typedef struct {
+ TPM_KEY_BITS keyBits;
+ TPMI_ALG_SYM_MODE mode;
+} TPMS_SMS4_PARMS;
+#endif
+
+// Table 119 -- TPMS_KEYEDHASH_PARMS from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_HASH sign;
+ TPMI_ALG_KDF encrypt;
+} TPMS_KEYEDHASH_PARMS;
+
+// Table 120 -- TPMU_SYM_DEF from outputUnionDef <I/O>
+typedef union {
+#if AES == YES
+ TPMS_AES_PARMS aes;
+#endif
+#if SMS4 == YES
+ TPMS_SMS4_PARMS sms4;
+#endif
+#if XOR == YES
+ TPMS_XOR_PARMS xor;
+#endif
+
+} TPMU_SYM_DEF ;
+
+
+// Table 121 -- TPMT_SYM_DEF from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_SYM algorithm;
+ TPMU_SYM_DEF details;
+} TPMT_SYM_DEF;
+
+// Table 122 -- TPMT_SYM_DEF_OBJECT from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_SYM_OBJECT algorithm;
+ TPMU_SYM_DEF details;
+} TPMT_SYM_DEF_OBJECT;
+
+// Table 123 -- TPM2B_SYM_KEY from outputStructDef <I/O>
+typedef struct {
+ UINT16 keySize;
+ BYTE key[MAX_SYM_DATA];
+} TPM2B_SYM_KEY;
+
+// Table 124 -- TPMS_SENSITIVE_CREATE from outputStructDef <I>
+typedef struct {
+ TPM2B_AUTH userAuth;
+ TPM2B_SYM_KEY data;
+} TPMS_SENSITIVE_CREATE;
+
+// Table 125 -- TPM2B_SENSITIVE_CREATE from outputStructDef <I,S>
+typedef struct {
+ UINT16 size;
+ TPMS_SENSITIVE_CREATE sensitive;
+} TPM2B_SENSITIVE_CREATE;
+
+// Table 126 -- TPMS_SCHEME_PKCS1v1_5 from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+} TPMS_SCHEME_PKCS1v1_5;
+#endif
+
+// Table 127 -- TPMS_SCHEME_PSS from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+ UINT16 saltSize;
+} TPMS_SCHEME_PSS;
+#endif
+
+// Table 128 -- TPMS_SCHEME_ECDSA from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+} TPMS_SCHEME_ECDSA;
+#endif
+
+// Table 129 -- TPMS_SCHEME_ECDAA from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+} TPMS_SCHEME_ECDAA;
+#endif
+
+// Table 130 -- TPMS_SCHEME_HMAC from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+} TPMS_SCHEME_HMAC;
+#endif
+
+// Table 131 -- TPMU_SIG_SCHEME from outputUnionDef <I/O,S>
+typedef union {
+#if RSASSA_PKCS1v1_5 == YES
+ TPMS_SCHEME_PKCS1v1_5 pkcs1v1_5;
+#endif
+#if PSS == YES
+ TPMS_SCHEME_PSS pkcspss;
+#endif
+#if ECDSA == YES
+ TPMS_SCHEME_ECDSA ecdsa;
+#endif
+#if ECDAA == YES
+ TPMS_SCHEME_ECDAA ecdaa;
+#endif
+#if HMAC == YES
+ TPMS_SCHEME_HMAC hmac;
+#endif
+
+} TPMU_SIG_SCHEME ;
+
+
+// Table 132 -- TPMT_SIG_SCHEME from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_SIG_SCHEME scheme;
+ TPMU_SIG_SCHEME details;
+} TPMT_SIG_SCHEME;
+
+// Table 133 -- TPMS_SCHEME_MGF1 from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+} TPMS_SCHEME_MGF1;
+
+// Table 134 -- TPMS_SCHEME_KDF1_SP800_56a from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+} TPMS_SCHEME_KDF1_SP800_56a;
+#endif
+
+// Table 135 -- TPMS_SCHEME_KDF2 from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+} TPMS_SCHEME_KDF2;
+
+// Table 136 -- TPMS_SCHEME_KDF1_SP800_108 from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_HASH hashAlg;
+} TPMS_SCHEME_KDF1_SP800_108;
+
+// Table 137 -- TPMU_KDF_SCHEME from outputUnionDef <I/O,S>
+typedef union {
+#if MGF1 == YES
+ TPMS_SCHEME_MGF1 mgf1;
+#endif
+#if KDF1_SP800_56a == YES
+ TPMS_SCHEME_KDF1_SP800_56a kdf1_SP800_56a;
+#endif
+#if KDF2 == YES
+ TPMS_SCHEME_KDF2 kdf2;
+#endif
+#if KDF1_SP800_108 == YES
+ TPMS_SCHEME_KDF1_SP800_108 kdf1_sp800_108;
+#endif
+
+} TPMU_KDF_SCHEME ;
+
+
+// Table 138 -- TPMT_KDF_SCHEME from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_KDF scheme;
+ TPMU_KDF_SCHEME details;
+} TPMT_KDF_SCHEME;
+
+// Table 139 -- TPMI_ALG_RSA_SIG_SCHEME from outputType <I/O>
+#if RSA == YES
+typedef TPM2_ALG_ID TPMI_ALG_RSA_SIG_SCHEME;
+
+#endif
+
+// Table 140 -- TPMT_RSA_SIG_SCHEME from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ TPMI_ALG_RSA_SIG_SCHEME scheme;
+ TPMU_SIG_SCHEME details;
+} TPMT_RSA_SIG_SCHEME;
+#endif
+
+// Table 141 -- TPMS_RSA_PARMS from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ TPM_KEY_BITS keyBits;
+ UINT32 exponent;
+ TPMT_RSA_SIG_SCHEME sign;
+ TPMT_SYM_DEF_OBJECT symmetric;
+} TPMS_RSA_PARMS;
+#endif
+
+// Table 142 -- TPM2B_RSA_PUBLIC_KEY from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ UINT16 size;
+ BYTE buffer[MAX_RSA_KEY_BYTES];
+} TPM2B_RSA_PUBLIC_KEY;
+#endif
+
+// Table 143 -- TPM2B_RSA_PRIVATE_KEY from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ UINT16 size;
+ BYTE buffer[MAX_RSA_KEY_BYTES/2];
+} TPM2B_RSA_PRIVATE_KEY;
+#endif
+
+// Table 144 -- TPM_ECC_CURVE from outputConstDef <I/O>
+#if ECC == YES
+typedef TPM_ECC_CURVE_ID TPM_ECC_CURVE;
+
+#define TPM_ECC_NIST_P256 (TPM_ECC_CURVE)(0x0000)
+#define TPM_ECC_NIST_P384 (TPM_ECC_CURVE)(0x0001)
+#define TPM_ECC_NIST_P521 (TPM_ECC_CURVE)(0x0002)
+
+
+
+#endif
+
+// Table 145 -- TPM2B_ECC_PARAMETER from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ UINT16 size;
+ BYTE value[MAX_ECC_KEY];
+} TPM2B_ECC_PARAMETER;
+#endif
+
+// Table 146 -- TPMS_ECC_POINT from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPM2B_ECC_PARAMETER pointX;
+ TPM2B_ECC_PARAMETER pointY;
+} TPMS_ECC_POINT;
+#endif
+
+// Table 147 -- TPM2B_ECC_POINT from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ UINT16 size;
+ TPMS_ECC_POINT point;
+} TPM2B_ECC_POINT;
+#endif
+
+// Table 148 -- TPMI_ALG_ECC_SIG_SCHEME from outputType <I/O>
+#if ECC == YES
+typedef TPM2_ALG_ID TPMI_ALG_ECC_SIG_SCHEME;
+
+#endif
+
+// Table 149 -- TPMT_ECC_SIG_SCHEME from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPMI_ALG_ECC_SIG_SCHEME scheme;
+ TPMU_SIG_SCHEME details;
+} TPMT_ECC_SIG_SCHEME;
+#endif
+
+// Table 150 -- TPMS_ECC_PARMS from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPM_ECC_CURVE curveID;
+ TPMT_ECC_SIG_SCHEME sign;
+ TPMT_SYM_DEF_OBJECT symmetric;
+ TPMT_KDF_SCHEME kdf;
+} TPMS_ECC_PARMS;
+#endif
+
+// Table 151 -- TPMS_ALGORITHM_DETAIL_ECC from outputStructDef <O,S>
+typedef struct {
+ TPM_ECC_CURVE_ID curveID;
+ UINT16 keySize;
+ TPMT_KDF_SCHEME kdf;
+ TPMT_ECC_SIG_SCHEME sign;
+ TPM2B_ECC_PARAMETER p;
+ TPM2B_ECC_PARAMETER a;
+ TPM2B_ECC_PARAMETER b;
+ TPM2B_ECC_PARAMETER gX;
+ TPM2B_ECC_PARAMETER gY;
+ TPM2B_ECC_PARAMETER n;
+ TPM2B_ECC_PARAMETER h;
+} TPMS_ALGORITHM_DETAIL_ECC;
+
+// Table 152 -- TPMS_SIGNATURE_PKCS1v1_5 from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ TPMI_ALG_HASH hash;
+ TPM2B_RSA_PUBLIC_KEY sig;
+} TPMS_SIGNATURE_PKCS1v1_5;
+#endif
+
+// Table 153 -- TPMS_SIGNATURE_PSS from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ TPMI_ALG_HASH hash;
+ TPM2B_RSA_PUBLIC_KEY sig;
+ UINT16 saltSize;
+} TPMS_SIGNATURE_PSS;
+#endif
+
+// Table 154 -- TPMS_SIGNATURE_ECDSA from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPMI_ALG_HASH hash;
+ TPM2B_ECC_PARAMETER signatureR;
+ TPM2B_ECC_PARAMETER signatureS;
+} TPMS_SIGNATURE_ECDSA;
+#endif
+
+// Table 155 -- TPMU_SIGNATURE from outputUnionDef <I/O,S>
+typedef union {
+#if RSASSA_PKCS1v1_5 == YES
+ TPMS_SIGNATURE_PKCS1v1_5 pkcs1v1_5;
+#endif
+#if PSS == YES
+ TPMS_SIGNATURE_PSS pkcspss;
+#endif
+#if ECDSA == YES
+ TPMS_SIGNATURE_ECDSA ecdsa;
+#endif
+#if HMAC == YES
+ TPMT_HA hmac;
+#endif
+
+} TPMU_SIGNATURE ;
+
+
+// Table 156 -- TPMT_SIGNATURE from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_SIG_SCHEME sigAlg;
+ TPMU_SIGNATURE digest;
+} TPMT_SIGNATURE;
+
+// Table 157 -- TPMU_ENCRYPTED_SECRET from outputUnionDef <S>
+typedef union {
+#if ECC == YES
+ BYTE ecc[sizeof(TPMS_ECC_POINT)];
+#endif
+#if RSA == YES
+ BYTE rsa[MAX_RSA_KEY_BYTES];
+#endif
+#if AES == YES
+ BYTE aes[sizeof(TPM2B_DIGEST)];
+#endif
+#if SMS4 == YES
+ BYTE sms4[sizeof(TPM2B_DIGEST)];
+#endif
+#if KEYEDHASH == YES
+ BYTE keyedHash[sizeof(TPM2B_DIGEST)];
+#endif
+
+} TPMU_ENCRYPTED_SECRET ;
+
+
+// Table 158 -- TPM2B_ENCRYPTED_SECRET from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE secret[sizeof(TPMU_ENCRYPTED_SECRET)];
+} TPM2B_ENCRYPTED_SECRET;
+
+// Table 159 -- TPMI_ALG_PUBLIC from outputType <I/O>
+typedef TPM2_ALG_ID TPMI_ALG_PUBLIC;
+
+
+// Table 160 -- TPMS_PUBLIC_ID_SYM from outputStructDef <I/O>
+typedef struct {
+ TPM2B_DIGEST unique;
+} TPMS_PUBLIC_ID_SYM;
+
+// Table 161 -- PublicIDStructures from outputTypeDef <I/O>
+typedef TPMS_PUBLIC_ID_SYM TPMS_PUBLIC_ID_AES;
+typedef TPMS_PUBLIC_ID_SYM TPMS_PUBLIC_ID_SMS4;
+typedef TPMS_PUBLIC_ID_SYM TPMS_PUBLIC_ID_KEYEDHASH;
+
+// Table 162 -- TPM2B_PUBLIC_ID_RSA from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ UINT16 keySize;
+ BYTE key[MAX_RSA_KEY_BYTES];
+} TPM2B_PUBLIC_ID_RSA;
+#endif
+
+// Table 163 -- TPMS_PUBLIC_ID_ECC from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPM2B_ECC_PARAMETER qX;
+ TPM2B_ECC_PARAMETER qY;
+} TPMS_PUBLIC_ID_ECC;
+#endif
+
+// Table 164 -- TPMU_PUBLIC_PARMS from outputUnionDef <I/O,S>
+typedef union {
+#if RSA == YES
+ TPMS_RSA_PARMS rsaDetail;
+#endif
+#if ECC == YES
+ TPMS_ECC_PARMS eccDetail;
+#endif
+#if KEYEDHASH == YES
+ TPMS_KEYEDHASH_PARMS keyedHash;
+#endif
+#if AES == YES
+ TPMS_AES_PARMS aesDetail;
+#endif
+#if SMS4 == YES
+ TPMS_SMS4_PARMS sms4Detail;
+#endif
+
+} TPMU_PUBLIC_PARMS ;
+
+
+// Table 165 -- TPMU_PUBLIC_ID from outputUnionDef <I/O,S>
+typedef union {
+#if AES == YES
+ TPMS_PUBLIC_ID_AES aes;
+#endif
+#if SMS4 == YES
+ TPMS_PUBLIC_ID_SMS4 sms4;
+#endif
+#if KEYEDHASH == YES
+ TPMS_PUBLIC_ID_KEYEDHASH keyedHash;
+#endif
+#if RSA == YES
+ TPM2B_PUBLIC_ID_RSA rsa;
+#endif
+#if ECC == YES
+ TPMS_PUBLIC_ID_ECC ecc;
+#endif
+
+} TPMU_PUBLIC_ID ;
+
+
+// Table 166 -- TPMT_PUBLIC_PARMS from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_PUBLIC type;
+ TPMU_PUBLIC_PARMS parameters;
+} TPMT_PUBLIC_PARMS;
+
+// Table 167 -- TPMT_PUBLIC from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_PUBLIC type;
+ TPMI_ALG_HASH nameAlg;
+ TPMA_OBJECT objectAttributes;
+ TPM2B_DIGEST authPolicy;
+ TPMU_PUBLIC_PARMS parameters;
+ TPMU_PUBLIC_ID unique;
+} TPMT_PUBLIC;
+
+// Table 168 -- TPM2B_PUBLIC from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ TPMT_PUBLIC publicArea;
+} TPM2B_PUBLIC;
+
+// Table 169 -- TPMS_SENSITIVE_SYM from outputStructDef <I/O>
+typedef struct {
+ TPM2B_DIGEST obfuscate;
+ TPM2B_SYM_KEY symKey;
+} TPMS_SENSITIVE_SYM;
+
+// Table 170 -- PrivateSymmetricStructures from outputTypeDef <I/O>
+typedef TPMS_SENSITIVE_SYM TPMS_SENSITIVE_AES;
+typedef TPMS_SENSITIVE_SYM TPMS_SENSITIVE_SMS4;
+typedef TPMS_SENSITIVE_SYM TPMS_SENSITIVE_KEYEDHASH;
+
+// Table 171 -- TPMS_SENSITIVE_RSA from outputStructDef <I/O>
+#if RSA == YES
+typedef struct {
+ UINT16 keySize;
+ BYTE key[(MAX_RSA_KEY_BYTES+1)/2];
+ TPM2B_SYM_KEY symKey;
+} TPMS_SENSITIVE_RSA;
+#endif
+
+// Table 172 -- TPMS_SENSITIVE_ECC from outputStructDef <I/O>
+#if ECC == YES
+typedef struct {
+ TPM2B_ECC_PARAMETER key;
+ TPM2B_SYM_KEY symKey;
+} TPMS_SENSITIVE_ECC;
+#endif
+
+// Table 173 -- TPMU_SENSITIVE_COMPOSITE from outputUnionDef <I/O,S>
+typedef union {
+#if RSA == YES
+ TPMS_SENSITIVE_RSA rsaDetail;
+#endif
+#if ECC == YES
+ TPMS_SENSITIVE_ECC eccDetail;
+#endif
+#if KEYEDHASH == YES
+ TPMS_SENSITIVE_SYM bitsDetail;
+#endif
+#if AES == YES
+ TPMS_SENSITIVE_SYM aesDetail;
+#endif
+#if SMS4 == YES
+ TPMS_SENSITIVE_SYM sms4Detail;
+#endif
+
+} TPMU_SENSITIVE_COMPOSITE ;
+
+
+// Table 174 -- TPMT_SENSITIVE from outputStructDef <I/O>
+typedef struct {
+ TPMI_ALG_PUBLIC sensitiveType;
+ TPM2B_AUTH authValue;
+ TPMU_SENSITIVE_COMPOSITE sensitive;
+} TPMT_SENSITIVE;
+
+// Table 175 -- TPM2B_SENSITIVE from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ TPMT_SENSITIVE sensitiveArea;
+} TPM2B_SENSITIVE;
+
+// Table 176 -- TPMS_ENCRYPT from outputStructDef <I/O,S>
+typedef struct {
+ TPM2B_DIGEST integrity;
+ TPMT_SENSITIVE sensitive;
+} TPMS_ENCRYPT;
+
+// Table 177 -- TPM2B_PRIVATE from outputStructDef <I/O,S>
+typedef struct {
+ UINT16 size;
+ BYTE data[sizeof(TPMS_ENCRYPT)];
+} TPM2B_PRIVATE;
+
+// Table 178 -- TPMS_ID_OBJECT from outputStructDef <I/O,S>
+typedef struct {
+ TPM2B_DIGEST integrity;
+ TPM2B_DIGEST protector;
+} TPMS_ID_OBJECT;
+
+// Table 179 -- TPM2B_ID_OBJECT from outputStructDef <I/O,S>
+typedef struct {
+ UINT16 size;
+ BYTE credential[sizeof(TPMS_ID_OBJECT)];
+} TPM2B_ID_OBJECT;
+
+// Table 180 -- TPM_NV_INDEX from outputBitDef <S>
+typedef struct {
+ unsigned int index : 21;
+ unsigned int space : 3;
+ unsigned int RH_NV : 8;
+} TPM2_NV_INDEX ;
+
+// Table 182 -- TPMA_NV from outputBitDef <I/O>
+typedef struct {
+ unsigned int TPMA_NV_PPWRITE : 1;
+ unsigned int TPMA_NV_OWNERWRITE : 1;
+ unsigned int TPMA_NV_AUTHWRITE : 1;
+ unsigned int TPMA_NV_POLICYWRITE : 1;
+ unsigned int TPMA_NV_COUNTER : 1;
+ unsigned int TPMA_NV_BITS : 1;
+ unsigned int TPMA_NV_EXTEND : 1;
+ unsigned int reserved8 : 4;
+ unsigned int TPMA_NV_WRITELOCKED : 1;
+ unsigned int TPMA_NV_WRITEALL : 1;
+ unsigned int TPMA_NV_WRITEDEFINE : 1;
+ unsigned int TPMA_NV_WRITE_STCLEAR : 1;
+ unsigned int TPMA_NV_GLOBALLOCK : 1;
+ unsigned int TPMA_NV_PPREAD : 1;
+ unsigned int TPMA_NV_OWNERREAD : 1;
+ unsigned int TPMA_NV_AUTHREAD : 1;
+ unsigned int TPMA_NV_POLICYREAD : 1;
+ unsigned int reserved18 : 5;
+ unsigned int TPMA_NV_NO_DA : 1;
+ unsigned int TPMA_NV_ORDERLY : 1;
+ unsigned int TPMA_NV_CLEAR_STCLEAR : 1;
+ unsigned int TPMA_NV_READLOCKED : 1;
+ unsigned int TPMA_NV_WRITTEN : 1;
+ unsigned int TPMA_NV_PLATFORMCREATE : 1;
+ unsigned int TPMA_NV_READ_STCLEAR : 1;
+} TPMA_NV ;
+
+// Table 183 -- TPMS_NV_PUBLIC from outputStructDef <I/O>
+typedef struct {
+ TPMI_RH_NV_INDEX nvIndex;
+ TPMI_ALG_HASH nameAlg;
+ TPMA_NV attributes;
+ TPM2B_DIGEST authPolicy;
+ UINT16 dataSize;
+} TPMS_NV_PUBLIC;
+
+// Table 184 -- TPM2B_NV_PUBLIC from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ TPMS_NV_PUBLIC nvPublic;
+} TPM2B_NV_PUBLIC;
+
+// Table 185 -- TPM2B_CONTEXT from outputStructDef <I/O>
+typedef struct {
+ UINT16 size;
+ BYTE contextData[MAX_CONTEXT_SIZE];
+} TPM2B_CONTEXT;
+
+// Table 186 -- TPMS_CONTEXT from outputStructDef <I/O>
+typedef struct {
+ UINT32 sequence;
+ TPMI_DH_CONTEXT savedHandle;
+ TPM2B_CONTEXT contextBlob;
+} TPMS_CONTEXT;
+
+// Table 187 -- TPMS_CREATION_DATA from outputStructDef <O,S>
+typedef struct {
+ TPML_PCR_SELECTION pcrSelect;
+ TPM2B_DIGEST pcrDigest;
+ TPMA_LOCALITY locality;
+ TPM2_ALG_ID parentNameAlg;
+ TPM2B_NAME parentName;
+ TPM2B_NAME parentQualifiedName;
+ TPM2B_DATA outsideInfo;
+} TPMS_CREATION_DATA;
+
+// Table 188 -- TPM2B_CREATION_DATA from outputStructDef <O,S>
+typedef struct {
+ UINT16 size;
+ TPMS_CREATION_DATA creationData;
+} TPM2B_CREATION_DATA;
+
+#pragma pack (pop)
+#endif
diff --git a/Core/EM/TCG2/Common/Tpm20Includes/Tpm20Includes.cif b/Core/EM/TCG2/Common/Tpm20Includes/Tpm20Includes.cif
new file mode 100644
index 0000000..55d6848
--- /dev/null
+++ b/Core/EM/TCG2/Common/Tpm20Includes/Tpm20Includes.cif
@@ -0,0 +1,10 @@
+<component>
+ name = "Tpm20Includes"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Common\Tpm20Includes"
+ RefName = "Tpm20Includes"
+[files]
+"Tpm20.h"
+"Tpm20Pei.h"
+"TrEEProtocol.h"
+<endComponent>
diff --git a/Core/EM/TCG2/Common/Tpm20Includes/Tpm20Pei.h b/Core/EM/TCG2/Common/Tpm20Includes/Tpm20Pei.h
new file mode 100644
index 0000000..f372b45
--- /dev/null
+++ b/Core/EM/TCG2/Common/Tpm20Includes/Tpm20Pei.h
@@ -0,0 +1,32 @@
+#ifndef TPM_2_0_PEI_H
+#define TPM_2_0_PEI_H
+
+#include <Tpm20Includes\Tpm20.h>
+
+#pragma pack(push, 1)
+
+typedef struct _TPM2_Startup{
+ TPMI_ST_COMMAND_TAG tag;
+ UINT32 CommandSize;
+ TPM_CC CommandCode;
+ TPM_SU StartupType;
+}TPM2_Startup_Cmd;
+
+typedef struct _TPM2_SelfTest{
+ TPMI_ST_COMMAND_TAG tag;
+ UINT32 CommandSize;
+ TPM_CC CommandCode;
+ TPMI_YES_NO SelfTestType;
+}TPM2_SelfTest;
+
+typedef struct _TPM2_Startup_Resp{
+ TPM_ST tag;
+ UINT32 ResponsSize;
+ TPM_RC ResponseCode;
+}TPM2_Common_RespHdr;
+
+#pragma pack(pop)
+
+EFI_STATUS Tpm20PeiSendStartup(IN EFI_PEI_SERVICES **PeiServices);
+EFI_STATUS Tpm20PeiSelfTest();
+#endif \ No newline at end of file
diff --git a/Core/EM/TCG2/Common/Tpm20Includes/TrEEProtocol.h b/Core/EM/TCG2/Common/Tpm20Includes/TrEEProtocol.h
new file mode 100644
index 0000000..c94df74
--- /dev/null
+++ b/Core/EM/TCG2/Common/Tpm20Includes/TrEEProtocol.h
@@ -0,0 +1,152 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+
+#ifndef TREE_PROTOCOL_H
+
+#define TREE_PROTOCOL_H
+
+#define EFI_TREE_SERVICE_BINDING_PROTOCOL_GUID \
+{0x4cf01d0a, 0xc48c, 0x4271, 0xa2, 0x2a, 0xad, 0x8e, 0x55, 0x97,\
+ 0x81, 0x88}
+
+#define EFI_TREE_PROTOCOL_GUID \
+{0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2,\
+ 0x72, 0x0f}
+
+typedef struct _EFI_TREE_PROTOCOL EFI_TREE_PROTOCOL;
+
+//#pragma pack(push,1) // Byte align structures
+
+typedef struct _TREE_VERSION {
+ UINT8 Major;
+ UINT8 Minor;
+} TREE_VERSION;
+
+typedef UINT32 TREE_EVENT_LOG_BITMAP;
+typedef UINT32 TREE_EVENT_LOG_FORMAT;
+#define TREE_EVENT_LOG_FORMAT_TCG_1_2 0x00000001
+
+#define TREE_STRUCTURE_VERSION_MAJOR (1)
+#define TREE_STRUCTURE_VERSION_MINOR (0)
+
+#define TREE_PROTOCOL_VERSION_MAJOR (1)
+#define TREE_PROTOCOL_VERSION_MINOR (0)
+
+typedef struct _TREE_BOOT_SERVICE_CAPABILITY {
+ UINT8 Size;
+ TREE_VERSION StructureVersion;
+ TREE_VERSION ProtocolVersion;
+ UINT32 HashAlgorithmBitmap;
+ TREE_EVENT_LOG_BITMAP SupportedEventLogs;
+ BOOLEAN TrEEPresentFlag;
+ UINT16 MaxCommandSize;
+ UINT16 MaxResponseSize;
+ UINT32 ManufacturerID;
+} TREE_BOOT_SERVICE_CAPABILITY;
+
+#define TREE_BOOT_HASH_ALG_SHA1 0x00000001
+#define TREE_BOOT_HASH_ALG_SHA256 0x00000002
+#define TREE_BOOT_HASH_ALG_SHA384 0x00000004
+#define TREE_BOOT_HASH_ALG_SHA512 0x00000008
+
+#define TREE_EXTEND_ONLY 0x0000000000000001
+#define PE_COFF_IMAGE 0x0000000000000010
+
+//#define EV_EFI_VARIABLE_DRIVER_CONFIG 0x80000001
+//#define EV_EFI_VARIABLE_AUTHORITY 0x800000E0
+typedef UINT32 TCG_EVENTTYPE;
+typedef UINT32 TCG_PCRINDEX;
+
+#pragma pack(push, 1) // Byte align structures
+
+typedef UINT32 TrEE_PCRINDEX;
+typedef UINT32 TrEE_EVENTTYPE;
+typedef UINT32 TREE_EVENTLOGTYPE;
+
+typedef struct _TrEE_EVENT_HEADER {
+ UINT32 HeaderSize;
+ UINT16 HeaderVersion;
+ TrEE_PCRINDEX PCRIndex;
+ TrEE_EVENTTYPE EventType;
+} TrEE_EVENT_HEADER;
+
+typedef struct _TrEE_EVENT {
+ UINT32 Size;
+ TrEE_EVENT_HEADER Header;
+ UINT8 Event[1];
+} TrEE_EVENT;
+
+#pragma pack(pop) // Byte align structures
+
+#define SIZE_OF_TrEE_EVENT OFFSET_OF (TrEE_EVENT, Event)
+
+typedef
+EFI_STATUS
+(EFIAPI *EFI_TREE_GET_CAPABILITY) (
+ IN EFI_TREE_PROTOCOL *This,
+ IN OUT TREE_BOOT_SERVICE_CAPABILITY *ProtocolCapability
+);
+
+typedef
+EFI_STATUS
+(EFIAPI *EFI_TREE_GET_EVENT_LOG) (
+ IN EFI_TREE_PROTOCOL *This,
+ IN TREE_EVENTLOGTYPE EventLogFormat,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLocation,
+ OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry,
+ OUT BOOLEAN *EventLogTruncated
+);
+
+typedef
+EFI_STATUS
+(EFIAPI * EFI_TREE_HASH_LOG_EXTEND_EVENT) (
+ IN EFI_TREE_PROTOCOL *This,
+ IN UINT64 Flags,
+ IN EFI_PHYSICAL_ADDRESS DataToHash,
+ IN UINT64 DataToHashLen,
+ IN TrEE_EVENT *Event
+);
+
+typedef
+EFI_STATUS
+(EFIAPI *EFI_TREE_SUBMIT_COMMAND) (
+ IN EFI_TREE_PROTOCOL *This,
+ IN UINT32 InputParameterBlockSize,
+ IN UINT8 *InputParameterBlock,
+ IN UINT32 OutputParameterBlockSize,
+ IN UINT8 *OutputParameterBlock
+);
+
+struct _EFI_TREE_PROTOCOL {
+ EFI_TREE_GET_CAPABILITY GetCapability;
+ EFI_TREE_GET_EVENT_LOG GetEventLog;
+ EFI_TREE_HASH_LOG_EXTEND_EVENT HashLogExtendEvent;
+ EFI_TREE_SUBMIT_COMMAND SubmitCommand;
+};
+
+#endif //TREE_PROTOCOL_H
+
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Core/EM/TCG2/Common/TpmDxe.c b/Core/EM/TCG2/Common/TpmDxe.c
new file mode 100644
index 0000000..662e91a
--- /dev/null
+++ b/Core/EM/TCG2/Common/TpmDxe.c
@@ -0,0 +1,545 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TpmDxe.h
+
+ Abstract:
+
+ DXE driver for TPM devices
+
+ --*/
+
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TpmDxe.c 2 4/21/14 3:17p Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 4/21/14 3:17p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/TpmDxe.c $
+//
+// 2 4/21/14 3:17p Fredericko
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 2 3/11/14 6:35p Fredericko
+// [TAG] EIP151925
+// [Category] New Feature
+// [Description] Changes for TcgGeneric Regression Testing
+//
+// 1 10/08/13 12:03p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 2:00p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 13 11/14/11 1:27p Fredericko
+// Changes for Tcgprotocol interface. Function is currently not used.
+//
+// 12 3/31/11 4:57p Fredericko
+// Changes for TCG_LEGACY support
+//
+// 11 3/29/11 1:12p Fredericko
+//
+// 10 3/28/11 2:19p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 9 5/19/10 5:31p Fredericko
+// Included File Header
+// Included File Revision History
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TpmDxe.c
+//
+// Description:
+// Abstracted functions for Tpm protocol are defined here
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include "TcgTpm12.h"
+#include <TpmLib.h>
+#include <Protocol\TpmDevice\TpmDevice.h>
+#include <AmiDxeLib.h>
+#include <token.h>
+#include "Tpm20CRBLib.h"
+
+
+#define _CR( Record, TYPE,\
+ Field )((TYPE*) ((CHAR8*) (Record) - (CHAR8*) &(((TYPE*) 0)->Field)))
+
+EFI_GUID TcgGuid = AMI_TCG_RESETVAR_HOB_GUID;
+
+VOID* LocateATcgHob (
+ UINTN NoTableEntries,
+ EFI_CONFIGURATION_TABLE *ConfigTable,
+ EFI_GUID *HOB_guid );
+
+#define TPM_DXE_PRIVATE_DATA_FROM_THIS( this ) \
+ _CR( this, TPM_DXE_PRIVATE_DATA, TpmInterface )
+
+typedef struct _TPM_DXE_PRIVATE_DATA
+{
+ EFI_TPM_DEVICE_PROTOCOL TpmInterface;
+ EFI_PHYSICAL_ADDRESS BaseAddr;
+} TPM_DXE_PRIVATE_DATA;
+
+FixedDelay(UINT32 dCount);
+
+static UINTN TpmFuncID;
+static TPMTransmitEntryStruct TpmEmptyBuf;
+static UINT32 TpmRet;
+static UINTN ReadytoBootVar = 0;
+
+
+#if TCG_LEGACY == 0
+EFI_STATUS
+EFIAPI TpmDxeInit(
+ IN EFI_TPM_DEVICE_PROTOCOL *This )
+{
+ EFI_STATUS Status;
+ volatile TPM_1_2_REGISTERS_PTR TpmReg;
+ TpmReg = (TPM_1_2_REGISTERS_PTR)(( UINTN ) (PORT_TPM_IOMEMBASE));
+ Status = TisRequestLocality(TpmReg);
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI TpmDxeClose(
+ IN EFI_TPM_DEVICE_PROTOCOL *This )
+{
+ EFI_STATUS Status;
+ volatile TPM_1_2_REGISTERS_PTR TpmReg;
+ TpmReg = (TPM_1_2_REGISTERS_PTR)(( UINTN ) (PORT_TPM_IOMEMBASE));
+ Status = TisReleaseLocality(TpmReg);
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI TpmDxeGetStatusInfo(
+ IN EFI_TPM_DEVICE_PROTOCOL *This )
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI TpmDxeTransmit(
+ IN EFI_TPM_DEVICE_PROTOCOL *This,
+ IN UINTN NoInBuffers,
+ IN TPM_TRANSMIT_BUFFER *InBuffers,
+ IN UINTN NoOutBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutBuffers )
+{
+ volatile TPM_1_2_REGISTERS_PTR TpmReg;
+ TpmReg = (TPM_1_2_REGISTERS_PTR)(( UINTN ) (PORT_TPM_IOMEMBASE));
+
+ TRACE(( TRACE_ALWAYS,"TpmReg.Access = %x \n", TpmReg->Access));
+ return TpmLibPassThrough(
+ TpmReg,
+ NoInBuffers,
+ InBuffers,
+ NoOutBuffers,
+ OutBuffers
+ );
+}
+
+#else
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TpmDxeInit
+//
+// Description: Call to OEM driver to initialize TPM.
+//
+// Input: IN EFI_TPM_DEVICE_PROTOCOL *This
+//
+// Returns: EFI_STATUS
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TpmDxeInit(
+ IN EFI_TPM_DEVICE_PROTOCOL *This )
+{
+ return EFI_SUCCESS; //init command is only sent once and done in PEI
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Name: TpmDxeClose
+//
+// Description: Close TPM connection for locality 0
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+///
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TpmDxeClose(
+ IN EFI_TPM_DEVICE_PROTOCOL *This )
+{
+ return EFI_SUCCESS;
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+//
+// Name: TpmDxeGetStatusInfo
+//
+// Description: GetStatus Info from MP driver
+//
+// Input: IN PEI_TPM_PPI *This,
+// IN EFI_PEI_SERVICES **PeiServices
+//
+// Output: EFI STATUS
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TpmDxeGetStatusInfo(
+ IN EFI_TPM_DEVICE_PROTOCOL * This
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: SetEfiOSTransitions
+//
+// Description: SetEfiOSTransitions
+//
+// Input: IN EFI_EVENT efiev
+// IN VOID *ctx
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+void SetEfiOSTransitions(
+ IN EFI_EVENT efiev,
+ IN VOID *ctx )
+{
+ ReadytoBootVar = 1;
+}
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: EfiOSReadyToBoot
+//
+// Description: Sets ready to boot callback on ready to boot
+//
+// Input: NONE
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI EfiOSReadyToBoot()
+{
+ EFI_EVENT ReadToBootEvent;
+ EFI_STATUS Status;
+
+ #if defined(EFI_EVENT_SIGNAL_READY_TO_BOOT)\
+ && EFI_SPECIFICATION_VERSION < 0x20000
+
+ Status = pBS->CreateEvent( EFI_EVENT_SIGNAL_READY_TO_BOOT,
+ EFI_TPL_CALLBACK,
+ SetEfiOSTransitions, NULL, &ReadToBootEvent );
+
+ #else
+ Status = CreateReadyToBootEvent( EFI_TPL_CALLBACK-1,
+ SetEfiOSTransitions,
+ NULL,
+ &ReadToBootEvent );
+ #endif
+
+ return Status;
+}
+
+
+
+EFI_STATUS
+EFIAPI EfiPreOSTransition(
+ IN EFI_TPM_DEVICE_PROTOCOL *This,
+ IN UINTN NoInBuffers,
+ IN TPM_TRANSMIT_BUFFER *InBuffers,
+ IN UINTN NoOutBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutBuffers )
+{
+ TPM_DXE_PRIVATE_DATA *Private;
+ TPM_1_2_REGISTERS_PTR TpmReg;
+ EFI_STATUS Status;
+
+ Private = TPM_DXE_PRIVATE_DATA_FROM_THIS( This );
+
+ TisRequestLocality(
+ (TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr);
+
+ TpmReg = (TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr;
+
+ Status = TpmLibPassThrough(
+ TpmReg,
+ NoInBuffers,
+ InBuffers,
+ NoOutBuffers,
+ OutBuffers
+ );
+
+ TisReleaseLocality(
+ (TPM_1_2_REGISTERS_PTR)( UINTN ) Private->BaseAddr);
+
+ return Status;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+//
+// Name: TpmDxeTransmit
+//
+// Description: Dxe Transmit Tcg Data
+//
+// Input: IN EFI_TPM_DEVICE_PROTOCOL *This,
+// IN UINTN NoInBuffers,
+// IN TPM_TRANSMIT_BUFFER *InBuffers,
+// IN UINTN NoOutBuffers,
+// IN OUT TPM_TRANSMIT_BUFFER *OutBuffers
+//
+// Output: EFI STATUS
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+
+EFI_STATUS
+EFIAPI TpmDxeTransmit(
+ IN EFI_TPM_DEVICE_PROTOCOL *This,
+ IN UINTN NoInBuffers,
+ IN TPM_TRANSMIT_BUFFER *InBuffers,
+ IN UINTN NoOutBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutBuffers )
+{
+ TPM_DXE_PRIVATE_DATA *Private;
+ TPMTransmitEntryStruct FillESI;
+ UINTN FuncID = (UINTN)MP_FUNCTION_TRANSMIT;
+ UINT32 Ret;
+ UINT8 *SHA_ARRAY_OUT = NULL;
+ BOOLEAN FillBuff = FALSE;
+ BOOLEAN Other = FALSE;
+ UINTN i = 0, loc = 0;
+ UINT8 *Tpm_SHA_ARRAY= NULL;
+ EFI_STATUS Status;
+
+
+ if(NoInBuffers == 0 || InBuffers == NULL || NoOutBuffers == 0 || OutBuffers == NULL)
+ return EFI_INVALID_PARAMETER;
+
+ if(ReadytoBootVar == 1)
+ {
+ return EfiPreOSTransition(This, NoInBuffers, InBuffers, NoOutBuffers, OutBuffers);
+ }
+
+
+ FillESI.dwInLen = 0;
+ FillESI.dwOutLen = 0;
+
+ for (; i < NoInBuffers; i++ )
+ {
+ FillESI.dwInLen += (UINT32)InBuffers[i].Size;
+ }
+
+ Status = pBS-> AllocatePool( EfiBootservicesData, FillESI.dwInLen, &Tpm_SHA_ARRAY);
+ if(EFI_ERROR(Status))return Status;
+
+
+ for (i = 0; i < NoOutBuffers; i++ )
+ {
+ FillESI.dwOutLen += (UINT32)OutBuffers[i].Size;
+ }
+
+ Status = pBS-> AllocatePool( EfiBootservicesData, FillESI.dwOutLen, &SHA_ARRAY_OUT );
+ if(EFI_ERROR(Status))return Status;
+
+
+ for (i = 0; i < NoInBuffers; i++ )
+ {
+ pBS->CopyMem(Tpm_SHA_ARRAY + loc,
+ InBuffers[i].Buffer,
+ InBuffers[i].Size );
+
+ loc += InBuffers[i].Size;
+ }
+
+ FillESI.pbInBuf = (UINT32)(EFI_PHYSICAL_ADDRESS) Tpm_SHA_ARRAY;
+ FillESI.pbOutBuf = (UINT32)(EFI_PHYSICAL_ADDRESS) SHA_ARRAY_OUT;
+
+ Private = TPM_DXE_PRIVATE_DATA_FROM_THIS( This );
+ TpmDxeCallMPDriver( FuncID, &FillESI, &Ret );
+
+ if ( Tpm_SHA_ARRAY != NULL )
+ {
+ pBS->FreePool( Tpm_SHA_ARRAY );
+ }
+
+ loc = 0;
+
+ for (i=0; i < NoOutBuffers; i++ )
+ {
+ pBS->CopyMem( OutBuffers[i].Buffer,
+ &SHA_ARRAY_OUT[loc],
+ OutBuffers[i].Size );
+ loc += (UINTN)OutBuffers[i].Size;
+ }
+
+ if ( SHA_ARRAY_OUT != NULL )
+ {
+ pBS->FreePool( SHA_ARRAY_OUT );
+ }
+
+ return EFI_SUCCESS;
+}
+
+#endif
+
+static TPM_DXE_PRIVATE_DATA mTpmPrivate = {
+ {
+ TpmDxeInit,
+ TpmDxeClose,
+ TpmDxeGetStatusInfo,
+ TpmDxeTransmit
+ },
+ TPM_BASE_ADDRESS
+};
+
+
+
+
+EFI_STATUS
+EFIAPI TpmDxeEntry(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+#if TCG_LEGACY == 1
+ EFI_GUID gMpDriverHobGuid = EFI_TCG_MPDriver_HOB_GUID;
+ FAR32LOCALS *TempLoc = NULL;
+#endif
+
+#if TCG_LEGACY == 0
+ Status = IsTpmPresent((TPM_1_2_REGISTERS_PTR)( UINTN ) mTpmPrivate.BaseAddr );
+
+ if ( EFI_ERROR( Status ))
+ {
+ if(isTpm20CrbPresent())return EFI_SUCCESS;
+ return EFI_UNLOAD_IMAGE;
+ }
+#else
+ TempLoc = (FAR32LOCALS*)LocateATcgHob( pST->NumberOfTableEntries,
+ pST->ConfigurationTable,
+ &gMpDriverHobGuid );
+
+
+ if(TempLoc == NULL || TempLoc->Offset == NULL ) return EFI_NOT_FOUND;
+ Prepare2Thunkproc( TempLoc->Offset, TempLoc->Selector );
+ Status = EfiOSReadyToBoot();
+#endif
+
+ Status = pBS->InstallMultipleProtocolInterfaces(
+ &ImageHandle,
+ &gEfiTpmDeviceProtocolGuid,
+ &mTpmPrivate.TpmInterface,
+ NULL
+ );
+
+ return Status;
+}
+
+
+
+EFI_GUID gEfiTpmDeviceProtocolGuid = EFI_TPM_DEVICE_PROTOCOL_GUID;
diff --git a/Core/EM/TCG2/Common/xTcgDxe.c b/Core/EM/TCG2/Common/xTcgDxe.c
new file mode 100644
index 0000000..4e2d21f
--- /dev/null
+++ b/Core/EM/TCG2/Common/xTcgDxe.c
@@ -0,0 +1,1835 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/xTcgDxe.c 2 6/14/14 12:28a Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 6/14/14 12:28a $
+//**********************************************************************
+// Revision History
+// ----------------\
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgDxe/xTcgDxe.c $
+//
+// 2 6/14/14 12:28a Fredericko
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 2 10/31/13 11:20a Fredericko
+//
+// 1 10/08/13 12:03p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 2:01p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 105 12/10/12 6:24p Fredericko
+//
+// 104 12/03/12 11:01p Fredericko
+// [TAG] EIP104961
+// [Category] Bug Fix
+// [Severity] Minor
+// [Symptom] UEFI 2.3.1 SCT test failed in Generic\EfiCompliant case.
+// The VariableAttribute of SecureBoot is not correct.
+// [RootCause] Changes to Secureboot module
+// [Solution] Remove secureboot variable check in Tcg
+// [Files] AmiTcgPlatformDxe.c
+// xTcgdxe.c
+//
+// 103 10/30/12 11:31a Fredericko
+//
+// 102 9/13/12 5:09p Fredericko
+// [TAG] EIP96217
+// [Category] Bug Fix
+// [Severity] Normal
+// [Symptom] AMIUEFI: Only one EV_EFI_VARIABLE_AUTHORITY event instead
+// of two when an EFI application or driver is not executed because of a
+// Secure Boot violation and then booted into Windows ( Winqual Bug ID :
+// 958465 )
+// [RootCause] Not measuring Subsequent Certificate Authority that can
+// be loaded after boot before ExitBootServices is called
+// [Solution] Measuring all Subsequent Certificate Authority that can be
+// loaded after boot before ExitBootServices is called
+// Also EIP [96218]: Measure Zero Events for when SecureBootSupport is
+// enabled but Keys are not installed
+// [Files] xTcgDxe.c
+// AmiTcgPlatformDxe.c
+//
+// 101 5/09/12 3:52p Fredericko
+// Changes for the measurement for Certificate Authority for secureboot.
+//
+// 100 4/28/12 3:28p Fredericko
+// Changed When gpt is measured as well as put Perf macro for DP
+// information.
+//
+// 99 4/19/12 5:57p Fredericko
+// EIP: 85771. Fixes for measurement of gpt partitions on EFI platform.
+// First boot scenario after flashing was failing sometimes.
+//
+// 97 3/19/12 6:32p Fredericko
+// [TAG] EIP82769
+// [Category] Improvement
+// [Description] Firmware updates disable the TPM when Firmware update
+// is done
+// [Files] xTcgPei.c, xTcgDxe.c, TcgDxe.c
+//
+// 96 12/15/11 3:25p Fredericko
+//
+// 95 12/12/11 3:37p Fredericko
+// [TAG] EIP76865
+// [Category] Improvement
+// [Description] Dual Support for TCM and TPM. System could hang in TXT
+// if txt is enabled in setup
+// [Files] AmiTcgPlatfompeilib.c, AmiTcgPlatformPpi.cif,
+// AmiTcgPlatformPpi.h, AmiTcgPlatformProtocol.cif,
+// AmiTcgPlatformProtocol.h,
+// EMpTcmPei.c, TcgDxe.cif, TcgPei.cif, TcgPeiAfterMem.cif,
+// TcgPeiAfterMem.mak, TcgTcmPeiAfterMem.c, xTcgDxe.c, xTcgPei.c,
+// xTcgPeiAfterMem.c
+//
+// 94 11/17/11 2:31p Fredericko
+// Changes for AmiTcgSetup for cases when TPM is plug into board after
+// first boot.
+//
+// 93 10/26/11 3:15p Fredericko
+// Changes for First boot scenerio and when Tcg Support is enabled and
+// Disabled
+//
+// 92 10/10/11 12:06a Fredericko
+// [TAG] EIP70220
+// [Category] Improvement
+// [Description] Remove dependency on CSM
+// [Files] TcgLegacy.sdl
+// AmiTcgPlatformDxe.c
+// AmiTcgPlatformDxe.h
+// xTcgDxe.c
+//
+// 91 9/27/11 10:26p Fredericko
+// [TAG] EIP67286
+// [Category] Improvement
+// [Description] changes for Tcg Setup policy
+// [Files] Tcg.sdl
+// TcgPei.cif
+// TcgPei.mak
+// xtcgPei.c
+// xTcgPeiAfterMem.c
+// TcgPeiAfterMem.mak
+// TcgDxe.cif
+// TcgDxe.mak
+// xTcgDxe.c
+// AmiTcgPlatformPeilib.c
+// AmiTcgPlatformDxelib.c
+//
+// 90 9/03/11 8:05p Fredericko
+//
+// 89 8/29/11 6:50p Fredericko
+// [TAG] EIP0000
+// [Category] Improvement
+// [Description] Tcg Setup improvement. Logic for when Tcgsupport is
+// enabled.
+// [Files] xtcgdxe.c
+//
+// 88 4/18/11 5:00p Fredericko
+//
+// 87 3/29/11 9:17p Fredericko
+// Don't install platform protocol if there is a TPM device error from
+// startup command or selftest
+//
+// 86 3/29/11 1:13p Fredericko
+//
+// 85 3/28/11 2:20p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 82 10/07/10 10:37a Fredericko
+// [TAG] EIP45667
+// [Category] BUG FIX
+// [Severity] Normal
+// [Symptom] Fail to get AMITSEVar
+// [RootCause] Uninitialized variable
+// [Solution] Initialize Size variable in prompt_operation function
+// [Files] xtcgdxe.c
+//
+// 81 9/23/10 6:12p Fredericko
+// [TAG] EIP42580
+// [Category] BUG FIX
+// [Severity] Normal
+// [Symptom] TPM prompt message override on LOGO mode
+// [RootCause] Proper SDL token comparism
+// [Solution] Use proper SDL token comparism
+// [Files] xtcgdxe.c
+//
+// 80 8/31/10 2:18p Fredericko
+// Workaround TSE problem with using AMIpost Manager for string display.
+//
+// 79 8/19/10 5:28p Fredericko
+// Edit display string positions on screen.
+//
+// 78 8/13/10 11:06a Fredericko
+// [TAG] N\A
+// [Category] IMPROVEMENT
+// [Description] Support for core 4.6.4.x and UEFI 2.1 Specifications
+// [FILES] xTcgDxe.c, TPMPwd.c
+//
+// 77 8/10/10 6:11p Fredericko
+// String display operations changes.
+//
+// 76 8/09/10 3:49p Fredericko
+// UEFI 2.1 changes
+//
+// 75 8/09/10 2:23p Fredericko
+// UEFI 2.1 changes
+//
+// 74 8/04/10 5:18p Fredericko
+// Reset system after executing owner commands. Special case.
+//
+// 73 7/13/10 5:37p Fredericko
+//
+// 72 7/09/10 3:39p Fredericko
+// modified platform protocol
+//
+// 71 6/02/10 5:06p Fredericko
+// Do nothing on some TPM error scenerios. We were shutting down the
+// system before.
+//
+// 70 5/21/10 4:03p Fredericko
+// Hii String package changes
+//
+// 68 5/21/10 11:37a Rizwank
+// Changes to include proper strings token header when AMI_TCG_MESSAGE is
+// enabled
+// Use correct imagehandle name
+//
+// 67 5/20/10 5:37p Fredericko
+//
+//
+// 65 5/20/10 9:02a Fredericko
+// Included File Header
+// Code Beautification
+// EIP 37653
+//
+// 64 4/30/10 5:01p Fredericko
+// EIP 36943: Was not writing TPM results and clearing TPM request on a
+// special case.
+//
+// 63 4/21/10 11:50a Fredericko
+// Removal of functions that are no needed anymore for multi language
+// support.
+//
+// 62 3/23/10 8:42p Fredericko
+// TcgLegacy event moved to subcomponent
+//
+// 61 3/19/10 4:20p Fredericko
+// modified for legacy IO interface support
+//
+// 60 1/14/10 11:57a Fredericko
+// Physical presence lifetime lock support added.
+//
+// 59 12/31/09 2:52p Fredericko
+// modified to allow the setting of lifetime lock on physical presence
+//
+// 58 11/17/09 5:53p Fredericko
+// Check-in changes for PPI request that was lost in label 32...
+//
+// 57 10/10/09 5:11p Fredericko
+//
+// 56 9/15/09 6:22p Fredericko
+// Changed to not use CMOS for the case when a deactivated for Enable,
+// Activate and allow owner command.
+//
+// 55 8/19/09 1:58p Fredericko
+//
+// 54 8/19/09 10:54a Fredericko
+// Support to measure CPU microcode in Nested firmware volume.
+//
+// 53 8/14/09 4:22p Fredericko
+// Changed flow with Authentication and Setup Confirmation to rid of extra
+// reset in the flow.
+//
+// 52 7/29/09 11:17a Fredericko
+// 1. Create ACPI table for all ACPI NVS. including ACPI3.0
+// 2. If Setup request fails full reset the platform and re-execute the
+// command on next boot.
+// 3. Minor Compiler problem with error checking fixed.
+//
+// 1 6/10/09 4:56p Fasihm
+// Added fix for TCG support. Remove after TCG label is updated with
+// changes generically incorporated.
+//
+// 51 6/02/09 4:49p Fredericko
+//
+// 50 6/02/09 1:12p Fredericko
+//
+// 49 6/01/09 4:18p Fredericko
+// Changes added for TCM_SUPPORT
+//
+// 48 4/30/09 6:18p Fredericko
+// Updated Header Date
+//
+// 47 4/30/09 5:36p Fredericko
+// AMI company Header Address changes, Fixes when AMI_TCG_MESSAGE is
+// enabled. Build and display Fixes.
+//
+// 46 4/13/09 4:39p Fredericko
+//
+// 45 4/03/09 6:14p Fredericko
+// #define changes and coding standard changes
+//
+// 43 3/05/09 3:15p Fredericko
+// Changes for CoreSources dependency
+//
+// 42 2/05/09 5:37p Fredericko
+// Lots of changes done in relation to removing dependencies on EDK
+//
+// 41 1/02/09 5:36p Fredericko
+// Moving Measurement of event Separators to EFI phase from legacy phase.
+//
+// 39 6/02/08 8:34p Fredericko
+// update Setup with no hardware if TPM does not respond properly to
+// commands.
+//
+// 38 4/10/08 6:02p Fredericko
+// Mor implemenation changes. Currently supports upto 4GB.
+//
+// 37 4/10/08 5:31p Fredericko
+// Generic Measurement changes and bug fixes
+//
+// 36 2/27/08 8:50p Fredericko
+//
+// 35 2/27/08 5:57p Fredericko
+// TCG specification changes and code clean up
+//
+// 34 2/06/08 9:01p Fredericko
+// Changes for DTM WLK 1.1 and Physical Presence Lock before booting.
+//
+// 33 1/18/08 8:23p Fredericko
+// Generic changes for Tcg EFI measurements specification requirements
+//
+// 32 11/09/07 6:44p Fasihm
+// Removed CONFIRM_SETUP_CHANGE around update_cmos() as it is not needed
+// now.
+//
+// 31 10/23/07 12:36p Fredericko
+// Setup PPI bug fixes
+//
+// 30 10/08/07 9:16a Fredericko
+//
+// 29 9/26/07 2:46p Fredericko
+// Build in TRACE "TRACE" bugs
+//
+// 28 9/04/07 6:09p Fredericko
+// Changes made for new compiler swtich "\W4" to work
+//
+// 27 9/04/07 10:22a Fredericko
+// Measuring Embedded PciROM fix
+//
+// 26 8/09/07 2:20p Pats
+// Removed unnecessary extern reference.
+//
+// 25 8/09/07 11:34a Pats
+// Modified to support password authentication and state change
+// confirmation.
+//
+// 24 7/13/07 2:54p Rameshraju
+// Added the TPM post message and SDL tokens for the TPM key's
+//
+// 23 6/13/07 5:26p Fredericko
+// Measuring PCI option ROM fixes
+//
+// 22 6/08/07 6:36p Fredericko
+// New TPM feature to allow disabling and enabling TPM support.
+//
+// 21 5/22/07 7:24p Fredericko
+//
+// 20 5/22/07 3:51p Fredericko
+// Added TPM feature to report TPM status and ownership in setup
+//
+// 19 3/23/07 3:34p Fredericko
+// Display Correction for PPI request
+//
+// 18 3/19/07 9:07a Fredericko
+// Build issue fix
+//
+// 17 3/14/07 5:14p Fredericko
+// PPI print change and PPI bug fixes
+//
+// 16 3/12/07 11:45a Fredericko
+// Allow execution of TCG command if Tcg_Setup_enable and
+// TCG_setup_operation is requested
+//
+// 15 3/07/07 3:10p Fredericko
+// TCG_PPI bug fixes
+//
+// 14 3/06/07 1:02p Fasihm
+// Added the support for the TCG PPI support to the TCG module.
+//
+// 13 3/01/07 8:00p Fasihm
+// Changes made for the new Edk in both structures and APIs.
+//
+// 12 12/11/06 1:56p Fasihm
+// Added code for controlling with the Setup question TCG_SETUP.
+//
+// 11 11/15/06 11:16a Radhikav
+//
+// 10 11/13/06 3:47p Radhikav
+//
+// 9 11/03/06 6:34p Andriyn
+//
+// 8 11/02/06 9:59a Andriyn
+// Change: new features (PPI and Setup questions) are conditional under
+// SDL flag
+//
+// 7 10/06/06 5:16p Andriyn
+//
+// 6 8/22/06 1:30p Andriyn
+// MOR related changes
+//
+// 5 8/18/06 9:02a Andriyn
+// Refactor code
+//
+// 4 8/15/06 9:28a Andriyn
+//
+// 3 6/22/06 3:03p Andriyn
+//
+// 2 6/20/06 7:13p Andriyn
+// Changes due to protocols moved to MiscFramework
+//--------------------------------------------------------------------------
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: xTcgDxe.c
+//
+// Description:
+// Most Tcg DXE initialization and measurements are done here
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <EFI.h>
+#include <TcgCommon.h>
+#include <AmiLib.h>
+#include <token.h>
+
+#if SMBIOS_SUPPORT == 1
+ #include <SmBios.h>
+#endif
+
+#include <TcgMisc.h>
+#include "TcgPrivate.h"
+#include <AmiDxeLib.h>
+#include <TcgPrivate.h>
+#include <DiskIo.h>
+#include <BlockIo.h>
+#include "protocol\TcgService\TcgService.h"
+#include "protocol\TpmDevice\TpmDevice.h"
+#include "Protocol/CpuIo.h"
+#include "Protocol/FirmwareVolume.h"
+#include "Protocol/DevicePath.h"
+#include "Protocol/PciIo.h"
+#include "TcgPlatformSetupPolicy.h"
+#include <AmiTcgPlatformProtocol.h>
+#if (defined(TCGMeasureSecureBootVariables) && (TCGMeasureSecureBootVariables != 0))
+#include <ImageAuthentication.h>
+#endif
+
+
+//------------------------------------------------------------------------
+//Internal Structures
+//------------------------------------------------------------------------
+typedef struct _TCG_DXE_PRIVATE_DATA
+{
+ EFI_TCG_PROTOCOL TcgServiceProtocol;
+ EFI_TPM_DEVICE_PROTOCOL *TpmDevice;
+} TCG_DXE_PRIVATE_DATA;
+
+EFI_STATUS
+__stdcall TcgDxeCommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PCRIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue );
+
+
+#define TCG_DXE_PRIVATE_DATA_FROM_THIS( This ) \
+ _CR( This, TCG_DXE_PRIVATE_DATA, TcgServiceProtocol )
+//--------------------------------------------------------------------------
+//--------------------------------------------------------------------------
+
+#define GUID_VARIABLE_DECLARATION( Variable, Guid ) extern EFI_GUID Variable
+
+EFI_GUID gEfiTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID;
+EFI_GUID gDsdtGuidDxe = DSDT_GUID;
+EFI_GUID TcgEfiGlobalVariableGuid = TCG_EFI_GLOBAL_VARIABLE_GUID;
+EFI_GUID AmiTcgPlatformProtocolGuid = AMI_TCG_PLATFORM_PROTOCOL_GUID;
+EFI_GUID gEfiTcgPrivateInterfaceGuid = EFI_TCG_PRIVATE_INTERFACE_GUID;
+static BOOLEAN BootLaunchDone = FALSE;
+
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+
+#include <AcpiSupport.h>
+
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+EFI_STATUS EFIAPI TcgDxeHashLogExtendEvent (
+ IN EFI_TCG_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS HashData,
+ IN UINT64 HashDataLen,
+ IN TCG_ALGORITHM_ID AlgorithmId,
+ IN OUT TCG_PCR_EVENT *TCGLogData,
+ IN OUT UINT32 *evNum );
+
+EFI_STATUS
+EFIAPI
+TcgMeasureGptTable (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ );
+
+
+/////////////////////////////////////////////////
+#define AMI_VALID_BOOT_IMAGE_CERT_TBL_GUID \
+ { 0x6683D10C, 0xCF6E, 0x4914, 0xB5, 0xB4, 0xAB, 0x8E, 0xD7, 0x37, 0x0E, 0xD7 }
+//
+//
+// Data Table definition
+//
+typedef struct _AMI_VALID_CERT_IN_SIG_DB {
+ UINT32 SigOffset;
+ UINT32 SigLength;
+} AMI_VALID_CERT_IN_SIG_DB;
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: AppendDevicePath
+//
+// Description: Appends Two given Device Path
+//
+// Input: IN EFI_DEVICE_PATH_PROTOCOL *Path1
+// IN EFI_DEVICE_PATH_PROTOCOL *Path2
+//
+// Output: None
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+static
+EFI_DEVICE_PATH_PROTOCOL* TcgAppendDevicePath(
+ IN EFI_DEVICE_PATH_PROTOCOL *Path1,
+ IN EFI_DEVICE_PATH_PROTOCOL *Path2 )
+{
+ EFI_DEVICE_PATH_PROTOCOL *NewPath;
+ UINTN PathSize1, PathSize2;
+
+ if ( !Path1 && !Path2 )
+ {
+ return NULL;
+ }
+
+ PathSize1 = DPLength( Path1 );
+ PathSize2 = DPLength( Path2 );
+
+ if ( PathSize1 && PathSize2 )
+ {
+ PathSize1 -= sizeof (EFI_DEVICE_PATH_PROTOCOL);
+ }
+
+ pBS->AllocatePool( EfiBootServicesData,
+ PathSize1 + PathSize2,
+ (void**)&NewPath );
+
+ pBS->CopyMem( NewPath, Path1, PathSize1 );
+ pBS->CopyMem( (UINT8*)NewPath + PathSize1, Path2, PathSize2 );
+
+ return NewPath;
+}
+
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: EfiLibAllocatePool
+//
+// Description: Allocate BootServicesData pool.
+//
+// Input: AllocationSize - The size to allocate
+//
+// Output: Pointer of the buffer allocated.
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+
+VOID *
+EfiLibAllocatePool (
+ IN UINTN AllocationSize
+)
+{
+ VOID *Memory;
+
+ Memory = NULL;
+ pBS->AllocatePool (EfiBootServicesData, AllocationSize, &Memory);
+ return Memory;
+}
+
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: TcgEfiLibAllocateZeroPool
+//
+// Description: Allocate BootServicesData pool and zero the pool.
+//
+// Input: AllocationSize - The size to allocate
+//
+// Output: Pointer of the buffer allocated.
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+VOID *
+TcgEfiLibAllocateZeroPool (
+ IN UINTN AllocationSize
+ )
+{
+ VOID *Memory;
+
+ Memory = EfiLibAllocatePool (AllocationSize);
+ if (Memory != NULL) {
+ pBS->SetMem (Memory, AllocationSize, 0);
+ }
+
+ return Memory;
+}
+
+
+#if (defined(TCGMeasureSecureBootVariables) && (TCGMeasureSecureBootVariables != 0))
+EFI_STATUS
+MeasureCertificate(UINTN sizeOfCertificate,
+ UINT8 *pterCertificate)
+{
+ EFI_STATUS Status;
+ TCG_PCR_EVENT *TcgEvent = NULL;
+ EFI_GUID gEfiTcgProtocolGuid = EFI_TCG_PROTOCOL_GUID;
+ EFI_TCG_PROTOCOL *tcgSvc;
+ TCG_EFI_VARIABLE_DATA *VarLog;
+ EFI_PHYSICAL_ADDRESS Last;
+ UINT32 evNum;
+ BOOLEAN AlreadyMeasuredCert = FALSE;
+ UINTN i=0;
+ UINTN VarNameLength;
+ static BOOLEAN initialized = 0;
+ static TPM_DIGEST digestTrackingArray[10];
+ static TPM_DIGEST zeroDigest;
+ UINT8 *tempDigest = NULL;
+ UINT64 HashedDataLen = 20;
+
+ if(!initialized)
+ {
+ for(i=0;i<5; i++)
+ {
+ MemSet(digestTrackingArray[i].digest,20,0);
+ }
+ MemSet(zeroDigest.digest,20,0);
+ initialized = TRUE;
+ }
+
+ Status = pBS->LocateProtocol(&gEfiTcgProtocolGuid,
+ NULL, &tcgSvc );
+
+ if(EFI_ERROR(Status))return Status;
+
+ VarNameLength = Wcslen(L"db");
+ Status = pBS->AllocatePool( EfiBootServicesData,
+ _TPM_STRUCT_PARTIAL_SIZE( TCG_PCR_EVENT,Event )
+ + (UINT32)(sizeof(TCG_EFI_VARIABLE_DATA) + (VarNameLength
+ * sizeof(CHAR16)) + sizeOfCertificate - 3),
+ &TcgEvent);
+
+ if(EFI_ERROR(Status))return Status;
+
+ TcgEvent->PCRIndex = 7;
+ TcgEvent->EventType = 0x800000E0;
+
+ TcgEvent->EventSize = (UINT32)( sizeof (*VarLog) + VarNameLength
+ * sizeof (CHAR16) + sizeOfCertificate) - 3;
+
+ pBS->AllocatePool( EfiBootServicesData, TcgEvent->EventSize, &VarLog );
+
+ if ( VarLog == NULL ){
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ VarLog->VariableName = gEfiImageSecurityDatabaseGuid;
+ VarLog->UnicodeNameLength = VarNameLength;
+ VarLog->VariableDataLength = sizeOfCertificate;
+
+ pBS->CopyMem((CHAR16*)(VarLog->UnicodeName),
+ L"db",
+ VarNameLength * sizeof (CHAR16));
+
+ pBS->CopyMem((CHAR16*)(VarLog->UnicodeName) + VarNameLength,
+ pterCertificate,
+ sizeOfCertificate);
+
+ pBS->CopyMem( TcgEvent->Event,
+ VarLog,
+ TcgEvent->EventSize );
+
+ //before extending verify if we have already measured it.
+ tcgSvc->HashAll(tcgSvc,
+ (UINT8 *)VarLog,
+ TcgEvent->EventSize,
+ 4,
+ &HashedDataLen,
+ &tempDigest);
+
+ for(i=0; i<10; i++)
+ {
+ //tempDigest
+ if(!MemCmp(digestTrackingArray[i].digest, tempDigest, 20))
+ return EFI_SUCCESS; //already measured
+
+ if(!MemCmp(digestTrackingArray[i].digest, zeroDigest.digest, 20))
+ break; //we need to measure
+ }
+
+ pBS->CopyMem(digestTrackingArray[i].digest, tempDigest, 20);
+
+ Status = tcgSvc->HashLogExtendEvent(tcgSvc,
+ (EFI_PHYSICAL_ADDRESS)VarLog,
+ TcgEvent->EventSize,
+ 4,
+ TcgEvent,
+ &evNum,
+ &Last );
+
+ pBS->FreePool(TcgEvent);
+
+ return Status;
+}
+
+
+EFI_STATUS FindandMeasureSecureBootCertificate(BOOLEAN BootPolicy)
+{
+ EFI_STATUS Status;
+ UINTN VarSize = 0;
+ UINTN i=0;
+ UINT8 *SecureDBBuffer = NULL;
+ UINT8 *CertificateBuffer = NULL;
+ UINTN SizeofCertificate = 0;
+ EFI_GUID Certificateguid = AMI_VALID_BOOT_IMAGE_CERT_TBL_GUID;
+ AMI_VALID_CERT_IN_SIG_DB *CertInfo;
+ UINT8 *CertOffsetPtr = NULL;
+ static BOOLEAN NullKeysMeasured = FALSE;
+
+
+ if(BootPolicy == FALSE && BootLaunchDone == FALSE) return EFI_SUCCESS;
+ if(NullKeysMeasured == TRUE)return EFI_SUCCESS;
+
+ if(BootPolicy == TRUE && BootLaunchDone == FALSE)
+ {
+ Status = pRS->GetVariable(L"db",
+ &gEfiImageSecurityDatabaseGuid,
+ NULL,
+ &VarSize,
+ NULL);
+
+ if ( Status == EFI_BUFFER_TOO_SMALL )
+ {
+ pBS->AllocatePool( EfiBootServicesData, VarSize, &SecureDBBuffer );
+
+ if ( SecureDBBuffer != NULL )
+ {
+ Status = pRS->GetVariable(L"db",
+ &gEfiImageSecurityDatabaseGuid,
+ NULL,
+ &VarSize,
+ SecureDBBuffer);
+
+ if ( EFI_ERROR( Status ))
+ {
+ pBS->FreePool( SecureDBBuffer );
+ SecureDBBuffer = NULL;
+#if (defined(UnconfiguredSecureBootVariables) && (UnconfiguredSecureBootVariables == 0))
+ return EFI_NOT_FOUND;
+#endif
+ }
+ }
+
+ }else{
+#if (defined(UnconfiguredSecureBootVariables) && (UnconfiguredSecureBootVariables == 0))
+ return EFI_NOT_FOUND;
+#else
+ SecureDBBuffer = NULL;
+#endif
+ }
+ }
+
+ //we need to find the pointer in the EFI system table and work from
+ //there
+ CertInfo = NULL;
+ CertInfo = GetEfiConfigurationTable(pST, &Certificateguid);
+ if(CertInfo == NULL){
+ TRACE(( TRACE_ALWAYS,"db variable found SecCertificate Information not found in EFI System Table \n"));
+ }
+ if(CertInfo->SigLength == 0){
+ TRACE(( TRACE_ALWAYS,"SecCertificate Information found in EST but Information might be invalid \n"));
+ }
+
+ CertOffsetPtr = NULL;
+
+ if(CertInfo!=0)
+ {
+ CertOffsetPtr = (SecureDBBuffer + CertInfo->SigOffset);
+ SizeofCertificate = (UINTN)CertInfo->SigLength;
+ }else{
+ SizeofCertificate = 0;
+ }
+
+ if(SizeofCertificate == 0){
+ NullKeysMeasured = TRUE;
+ }
+
+ MeasureCertificate(SizeofCertificate,CertOffsetPtr);
+
+ if(SecureDBBuffer!=NULL){
+ pBS->FreePool( SecureDBBuffer );
+ }
+
+ return Status;
+}
+#endif
+
+
+
+
+//--------------------------------------------------------------------------------------------
+//Description: Measure a PE/COFF image into PCR 2 or 4 depending on Boot policy of 0 or 1
+//Arguments:
+// BootPolicy - Boolean value of 0 or 1 for PCR index 2 or 4.
+// ImageContext - Contains details about the image.
+// LinkTimeBase - Linking time Image Address
+// ImageType - EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION, BOOT_SERVICE_DRIVER, EFI_RUNTIME_DRIVER
+// DeviceHandle - Device identification handle
+// FilePath - Device File path
+//Output: EFI_SUCCESS - Image Measured successfully.
+//---------------------------------------------------------------------------------------------
+
+EFI_STATUS
+EFIAPI
+TcgMeasurePeImage (
+ IN BOOLEAN BootPolicy,
+ IN EFI_PHYSICAL_ADDRESS ImageAddress,
+ IN UINTN ImageSize,
+ IN UINTN LinkTimeBase,
+ IN UINT16 ImageType,
+ IN EFI_HANDLE DeviceHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath
+ )
+{
+
+ EFI_STATUS Status;
+ TCG_PCR_EVENT_HDR TcgEvent;
+ TCG_PCR_EVENT *TcgEventlog = NULL;
+ EFI_IMAGE_LOAD_EVENT *ImageLoad;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *FullPath;
+ UINT32 FullPathSize;
+ SHA1_CTX Sha1Ctx;
+ TCG_EFI_IMAGE_DOS_HEADER *DosHdr;
+ UINT32 PeCoffHeaderOffset;
+ TCG_EFI_IMAGE_NT_HEADERS *Hdr;
+ TCG_EFI_IMAGE_SECTION_HEADER *Section;
+ UINT8 *HashBase;
+ UINTN HashSize;
+ UINTN SumOfBytesHashed;
+ TCG_EFI_IMAGE_SECTION_HEADER *SectionHeader;
+ UINTN Index, iPos;
+ EFI_TCG_PROTOCOL *TcgProtocol;
+ EFI_TPM_DEVICE_PROTOCOL *TpmProtocol;
+ UINT32 EventNumber;
+ TCG_DIGEST *Sha1Digest = NULL;
+
+ ImageLoad = NULL;
+ FullPath = NULL;
+ SectionHeader = NULL;
+ FullPathSize = 0;
+
+ if(AutoSupportType()){
+ return EFI_SUCCESS;
+ }
+
+ Status = pBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, &TcgProtocol);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = pBS->LocateProtocol (&gEfiTpmDeviceProtocolGuid, NULL, &TpmProtocol );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+
+
+ if (DeviceHandle != NULL) {
+ //
+ // Skip images loaded from FVs
+ //
+ Status = pBS->OpenProtocol (
+ DeviceHandle,
+ &gEfiFirmwareVolumeProtocolGuid,
+ NULL,
+ NULL,
+ NULL,
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL
+ );
+ if (!EFI_ERROR (Status)) {
+ goto Done;
+ }
+ ASSERT (Status == EFI_UNSUPPORTED);
+
+ //
+ // Get device path for the device handle
+ //
+ Status = pBS->HandleProtocol (
+ DeviceHandle,
+ &gEfiDevicePathProtocolGuid,
+ &DevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ FullPath = TcgAppendDevicePath (DevicePath, FilePath);
+ FullPathSize = (UINT32)DPLength (FullPath);
+ }
+
+ //Allocate Event log memory
+ Status = pBS->AllocatePool( EfiBootServicesData,
+ _TPM_STRUCT_PARTIAL_SIZE( TCG_PCR_EVENT, Event )
+ + ((sizeof (*ImageLoad)
+ - sizeof (ImageLoad->DevicePath)) + FullPathSize),
+ &TcgEventlog );
+ //
+ // Determine destination PCR by BootPolicy
+ //
+ TcgEvent.PCRIndex = BootPolicy ? 4 : 2;
+ TcgEvent.EventSize = sizeof (*ImageLoad) - sizeof (ImageLoad->DevicePath);
+ TcgEvent.EventSize += FullPathSize;
+
+ switch (ImageType) {
+ case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
+ TcgEvent.EventType = EV_EFI_BOOT_SERVICES_APPLICATION;
+ break;
+ case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
+ TcgEvent.EventType = EV_EFI_BOOT_SERVICES_DRIVER;
+ break;
+ case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
+ TcgEvent.EventType = EV_EFI_RUNTIME_SERVICES_DRIVER;
+ break;
+ default:
+ TRACE(( TRACE_ALWAYS,
+ __FUNCTION__ ": Unknown subsystem type %d",
+ ImageType));
+
+ ASSERT (FALSE);
+ TcgEvent.EventType = ImageType;
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ //do measure images from ROM that call LoadImage themselves
+ // without the correct Devicepath
+ if(ImageType == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
+ && BootLaunchDone == FALSE){
+ return EFI_SUCCESS;
+ }
+
+
+ PERF_START(0,L"MeasurePeImg",NULL,0);
+
+ Status = pBS->AllocatePool( EfiBootServicesData,
+ TcgEvent.EventSize,
+ &ImageLoad );
+
+ if (ImageLoad == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
+
+ ImageLoad->ImageLocationInMemory = ImageAddress;
+ ImageLoad->ImageLengthInMemory = ImageSize;
+ ImageLoad->ImageLinkTimeAddress = LinkTimeBase;
+ ImageLoad->LengthOfDevicePath = FullPathSize;
+ pBS->CopyMem( ImageLoad->DevicePath, FullPath, FullPathSize );
+
+ //
+ // Check PE/COFF image
+ //
+ DosHdr = (TCG_EFI_IMAGE_DOS_HEADER *)(UINTN)ImageAddress;
+ PeCoffHeaderOffset = 0;
+ if (DosHdr->e_magic == TCG_EFI_IMAGE_DOS_SIGNATURE) {
+ PeCoffHeaderOffset = DosHdr->e_lfanew;
+ }
+ if (((TCG_EFI_TE_IMAGE_HEADER *)((UINT8 *)(UINTN)ImageAddress + PeCoffHeaderOffset))->Signature
+ == TCG_EFI_TE_IMAGE_HEADER_SIGNATURE) {
+ goto Done;
+ }
+
+ //
+ // PE/COFF Image Measurement
+ //
+ // NOTE: The following codes/steps are based upon the authenticode image hashing in
+ // PE/COFF Specification 8.0 Appendix A.
+ //
+ //
+
+ // 1. Load the image header into memory.
+
+ // 2. Initialize a SHA hash context.
+// Status = SHA1_init(TcgProtocol, &Sha1Ctx);
+ SHA1Init(&Sha1Ctx );
+
+ //
+ // Measuring PE/COFF Image Header;
+ // But CheckSum field and SECURITY data directory (certificate) are excluded
+ //
+ Hdr = (TCG_EFI_IMAGE_NT_HEADERS *)((UINT8 *)(UINTN)ImageAddress + PeCoffHeaderOffset);
+
+ //
+ // 3. Calculate the distance from the base of the image header to the image checksum address.
+ // 4. Hash the image header from its base to beginning of the image checksum.
+ //
+ HashBase = (UINT8 *)(UINTN)ImageAddress;
+ HashSize = (UINTN) ((UINT8 *)(&Hdr->OptionalHeader.CheckSum) - HashBase);
+
+/*Status = SHA1_update(TcgProtocol,
+ &Sha1Ctx,
+ HashBase,
+ HashSize
+ );
+*/
+ SHA1Update(&Sha1Ctx, HashBase, (u32)HashSize );
+
+ //
+ // 5. Skip over the image checksum (it occupies a single ULONG).
+ // 6. Get the address of the beginning of the Cert Directory.
+ // 7. Hash everything from the end of the checksum to the start of the Cert Directory.
+ //
+ HashBase = (UINT8 *) &Hdr->OptionalHeader.CheckSum + sizeof (UINT32);
+ HashSize = (UINTN) ((UINT8 *)(&Hdr->OptionalHeader.DataDirectory[TCG_EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - HashBase);
+
+/* Status = SHA1_update(TcgProtocol,
+ &Sha1Ctx,
+ HashBase,
+ HashSize
+ );
+*/
+ SHA1Update(&Sha1Ctx, HashBase, (u32)HashSize );
+
+ //
+ // 8. Skip over the Cert Directory. (It is sizeof(IMAGE_DATA_DIRECTORY) bytes.)
+ // 9. Hash everything from the end of the Cert Directory to the end of image header.
+ //
+ HashBase = (UINT8 *) &Hdr->OptionalHeader.DataDirectory[TCG_EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];
+ HashSize = Hdr->OptionalHeader.SizeOfHeaders -
+ (UINTN) ((UINT8 *)(&Hdr->OptionalHeader.DataDirectory[TCG_EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1]) - (UINT8 *)(UINTN)ImageAddress);
+
+/* Status = SHA1_update(TcgProtocol,
+ &Sha1Ctx,
+ HashBase,
+ HashSize
+ );
+*/
+ SHA1Update(&Sha1Ctx, HashBase, (u32)HashSize );
+
+ //
+ // 10. Set the SUM_OF_BYTES_HASHED to the size of the header
+ //
+ SumOfBytesHashed = Hdr->OptionalHeader.SizeOfHeaders;
+
+ //
+ // 11. Build a temporary table of pointers to all the IMAGE_SECTION_HEADER
+ // structures in the image. The 'NumberOfSections' field of the image
+ // header indicates how big the table should be. Do not include any
+ // IMAGE_SECTION_HEADERs in the table whose 'SizeOfRawData' field is zero.
+ //
+
+ Status = pBS->AllocatePool (EfiBootServicesData, sizeof (TCG_EFI_IMAGE_SECTION_HEADER) * Hdr->FileHeader.NumberOfSections, &SectionHeader);
+ if(SectionHeader==NULL)return EFI_OUT_OF_RESOURCES;
+ pBS->SetMem (SectionHeader, sizeof (TCG_EFI_IMAGE_SECTION_HEADER) * Hdr->FileHeader.NumberOfSections , 0);
+
+ //
+ // 12. Using the 'PointerToRawData' in the referenced section headers as
+ // a key, arrange the elements in the table in ascending order. In other
+ // words, sort the section headers according to the disk-file offset of
+ // the section.
+ //
+ Section = (TCG_EFI_IMAGE_SECTION_HEADER *) (
+ (UINT8 *)(UINTN)ImageAddress +
+ PeCoffHeaderOffset +
+ sizeof(UINT32) +
+ sizeof(TCG_EFI_IMAGE_FILE_HEADER) +
+ Hdr->FileHeader.SizeOfOptionalHeader
+ );
+ for (Index = 0; Index < Hdr->FileHeader.NumberOfSections; Index++) {
+ iPos = Index;
+ while ((iPos > 0) && (Section->PointerToRawData < SectionHeader[iPos - 1].PointerToRawData)) {
+ MemCpy (&SectionHeader[iPos], &SectionHeader[iPos - 1], sizeof(TCG_EFI_IMAGE_SECTION_HEADER));
+ iPos--;
+ }
+ MemCpy( &SectionHeader[iPos], Section,
+ sizeof(TCG_EFI_IMAGE_SECTION_HEADER));
+ Section += 1;
+ }
+
+ //
+ // 13. Walk through the sorted table, bring the corresponding section
+ // into memory, and hash the entire section (using the 'SizeOfRawData'
+ // field in the section header to determine the amount of data to hash).
+ // 14. Add the section's 'SizeOfRawData' to SUM_OF_BYTES_HASHED .
+ // 15. Repeat steps 13 and 14 for all the sections in the sorted table.
+ //
+ for (Index = 0; Index < Hdr->FileHeader.NumberOfSections; Index++) {
+ Section = (TCG_EFI_IMAGE_SECTION_HEADER *) &SectionHeader[Index];
+ if (Section->SizeOfRawData == 0) {
+ continue;
+ }
+ HashBase = (UINT8 *)(UINTN)ImageAddress + Section->PointerToRawData;
+ HashSize = (UINTN) Section->SizeOfRawData;
+/*
+ Status = SHA1_update(TcgProtocol,
+ &Sha1Ctx,
+ HashBase,
+ HashSize
+ );
+*/
+ SHA1Update(&Sha1Ctx, HashBase, (u32)HashSize );
+
+ SumOfBytesHashed += HashSize;
+ }
+
+ //
+ // 16. If the file size is greater than SUM_OF_BYTES_HASHED, there is extra
+ // data in the file that needs to be added to the hash. This data begins
+ // at file offset SUM_OF_BYTES_HASHED and its length is:
+ // FileSize - (CertDirectory->Size)
+ //
+ if (ImageSize > SumOfBytesHashed) {
+ HashBase = (UINT8 *)(UINTN)ImageAddress + SumOfBytesHashed;
+ HashSize = (UINTN)(ImageSize -
+ Hdr->OptionalHeader.DataDirectory[TCG_EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].Size -
+ SumOfBytesHashed);
+/*
+ Status = SHA1_update(TcgProtocol,
+ &Sha1Ctx,
+ HashBase,
+ HashSize
+ );
+*/
+ SHA1Update(&Sha1Ctx, HashBase, (u32)HashSize );
+ }
+
+ //
+ // 17. Finalize the SHA hash.
+ //
+// Status = SHA1_final(TcgProtocol, &Sha1Ctx, &Sha1Digest);
+ SHA1Final((unsigned char *)&Sha1Digest->digest, &Sha1Ctx);
+
+ pBS->CopyMem (&TcgEvent.Digest.digest,Sha1Digest->digest, sizeof (TcgEvent.Digest.digest));
+
+ //
+ // HashLogExtendEvent
+ //
+
+ //hash has been generated so extend it
+ TpmProtocol->Init(TpmProtocol);
+
+ Status = TcgDxeCommonExtend (
+ (void *)TcgProtocol,
+ TcgEvent.PCRIndex,
+ &TcgEvent.Digest,
+ Sha1Digest
+ );
+
+ TpmProtocol->Close(TpmProtocol);
+
+ if (!EFI_ERROR (Status)) {
+
+ //Now log the event
+ TcgEventlog->PCRIndex = TcgEvent.PCRIndex;
+ TcgEventlog->EventType = TcgEvent.EventType;
+ TcgEventlog->EventSize = TcgEvent.EventSize;
+ MemCpy(&TcgEventlog->Digest, &TcgEvent.Digest, sizeof(TCG_DIGEST));
+ MemCpy(&TcgEventlog->Event, ImageLoad, TcgEvent.EventSize);
+ Status = TcgProtocol->LogEvent(TcgProtocol, TcgEventlog, &EventNumber,0x01);
+ }
+
+ PERF_END(0,L"MeasurePeImg",NULL,0);
+
+ if(BootPolicy == TRUE && BootLaunchDone == FALSE){
+ PERF_START(0,L"MeasureGpt",NULL,0);
+ TcgMeasureGptTable(FullPath);
+ PERF_END(0,L"MeasureGpt",NULL,0);
+ }
+
+#if (defined(TCGMeasureSecureBootVariables) && (TCGMeasureSecureBootVariables != 0))
+ FindandMeasureSecureBootCertificate(BootPolicy);
+#endif
+
+ if(BootPolicy == TRUE && BootLaunchDone == FALSE){
+ BootLaunchDone = TRUE;
+ }
+
+ TpmProtocol->Close(TpmProtocol);
+
+Done:
+ if (ImageLoad != NULL) {
+ pBS->FreePool (ImageLoad);
+ }
+
+ if (TcgEventlog != NULL )
+ {
+ pBS->FreePool( TcgEventlog );
+ }
+ if (FullPathSize > 0) {
+ pBS->FreePool (FullPath);
+ }
+ if (SectionHeader != NULL) {
+ pBS->FreePool (SectionHeader);
+ }
+ return Status;
+}
+
+
+
+
+
+
+EFI_STATUS
+EFIAPI
+GptDevicePathToHandle (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ OUT EFI_HANDLE *GptHandle
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePathNode;
+ EFI_DEVICE_PATH_PROTOCOL *PreDevicePathNode;
+ HARDDRIVE_DEVICE_PATH *HdDevicePath;
+ EFI_HANDLE Handle;
+ BOOLEAN GptDiskFound;
+
+ NewDevicePathNode = TcgEfiLibAllocateZeroPool (DPLength (DevicePath));
+ MemCpy (NewDevicePathNode, DevicePath, DPLength (DevicePath));
+ DevicePathNode = NewDevicePathNode;
+
+ //
+ // The device should support blockIO protocol. Check it.
+ //
+ Status = pBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &DevicePathNode, &Handle);
+ if (EFI_ERROR (Status)) {
+ pBS->FreePool (NewDevicePathNode);
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Find the gpt partion on the given devicepath, if not, return.
+ //
+ GptDiskFound = FALSE;
+ PreDevicePathNode = NULL;
+ HdDevicePath = NULL;
+ DevicePathNode = NewDevicePathNode;
+ while (!IsDevicePathEnd (DevicePathNode)) {
+ //
+ // Find the Gpt partition
+ //
+ if (DevicePathType (DevicePathNode) == MEDIA_DEVICE_PATH &&
+ DevicePathSubType (DevicePathNode) == MEDIA_HARDDRIVE_DP) {
+ HdDevicePath = (HARDDRIVE_DEVICE_PATH *) DevicePathNode;
+ //
+ // Check whether it is a gpt partition or not
+ //
+ if (PreDevicePathNode != NULL &&
+ HdDevicePath->MBRType == MBR_TYPE_EFI_PARTITION_TABLE_HEADER &&
+ HdDevicePath->SignatureType == SIGNATURE_TYPE_GUID) {
+ GptDiskFound = TRUE;
+ break;
+ }
+ }
+ PreDevicePathNode = DevicePathNode;
+ DevicePathNode = NextDevicePathNode (DevicePathNode);
+ }
+ if (!GptDiskFound) {
+ pBS->FreePool (NewDevicePathNode);
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Change the device path to the parent device path and get the handle.
+ //
+ DevicePathNode->Type = 0xFF;
+ DevicePathNode->SubType = 0xFF;
+ DevicePathNode = NewDevicePathNode;
+ Status = pBS->LocateDevicePath (
+ &gEfiDiskIoProtocolGuid,
+ &DevicePathNode,
+ &Handle
+ );
+ if (EFI_ERROR (Status)) {
+ pBS->FreePool (NewDevicePathNode);
+ return Status;
+ }
+ *GptHandle = Handle;
+ pBS->FreePool (NewDevicePathNode);
+ return EFI_SUCCESS;
+}
+
+
+
+
+EFI_DEVICE_PATH_PROTOCOL *
+HandleBootDevicePath(
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath
+)
+{
+ EFI_STATUS Status;
+ EFI_HANDLE *Handle;
+ UINTN Count, i;
+ EFI_DEVICE_PATH_PROTOCOL *FullDevicePath=NULL;
+ HARDDRIVE_DEVICE_PATH *BootParitionDevicePath = (HARDDRIVE_DEVICE_PATH*)DevicePath;
+
+ Status = pBS->LocateHandleBuffer(ByProtocol,&gEfiBlockIoProtocolGuid,NULL,&Count,&Handle);
+ if (EFI_ERROR(Status)) return NULL;
+
+ for( i=0; i<Count; i++ )
+ {
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_DEVICE_PATH_PROTOCOL *PartitionDevicePath, *TmpDevicePath;
+ HARDDRIVE_DEVICE_PATH* PartitionNode;
+
+ Status = pBS->HandleProtocol(Handle[i],&gEfiBlockIoProtocolGuid,&BlockIo);
+ if (EFI_ERROR(Status))
+ continue;
+
+ // if this is not partition, continue
+ if (!BlockIo->Media->LogicalPartition)
+ continue;
+
+ Status = pBS->HandleProtocol(Handle[i],&gEfiDevicePathProtocolGuid,&PartitionDevicePath);
+ if (EFI_ERROR(Status))
+ continue;
+
+ // Get last node of the device path. It should be partition node
+ PartitionNode = (HARDDRIVE_DEVICE_PATH*)PartitionDevicePath;
+
+ for( TmpDevicePath = PartitionDevicePath;
+ !IsDevicePathEndType(TmpDevicePath);
+ TmpDevicePath=NextDevicePathNode(TmpDevicePath) )
+ {
+ PartitionNode = (HARDDRIVE_DEVICE_PATH*)TmpDevicePath;
+ }
+
+ //Check if our partition matches Boot partition
+ if (PartitionNode->Header.Type!=MEDIA_DEVICE_PATH || PartitionNode->Header.SubType!=MEDIA_HARDDRIVE_DP)
+ continue;
+
+ if ( PartitionNode->PartitionNumber==BootParitionDevicePath->PartitionNumber &&
+ PartitionNode->SignatureType==BootParitionDevicePath->SignatureType &&
+ !MemCmp(PartitionNode->Signature,BootParitionDevicePath->Signature,16) )
+ {
+ //Match found
+ FullDevicePath = TcgAppendDevicePath(PartitionDevicePath,NextDevicePathNode(DevicePath));
+ break;
+ }
+ }
+
+ pBS->FreePool(Handle);
+ return FullDevicePath;
+}
+
+
+EFI_STATUS
+EFIAPI
+TcgMeasureGptTable (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_DISK_IO_PROTOCOL *DiskIo;
+ TCG_EFI_PARTITION_TABLE_HEADER *PrimaryHeader;
+ TCG_EFI_PARTITION_ENTRY *PartitionEntry;
+ UINT8 *EntryPtr;
+ UINTN NumberOfPartition;
+ UINT32 Index;
+ TCG_PCR_EVENT *TcgEvent;
+ TCG_EFI_GPT_DATA *GptData;
+ EFI_GUID NullGuid = EFI_NULL_GUID;
+ EFI_HANDLE Handle;
+ EFI_TCG_PROTOCOL *TcgProtocol;
+ EFI_TPM_DEVICE_PROTOCOL *TpmProtocol;
+ UINT32 evNum;
+ EFI_PHYSICAL_ADDRESS Last;
+ UINTN GptIndex;
+
+ if(AutoSupportType()){
+ return EFI_SUCCESS;
+ }
+
+ Status = GptDevicePathToHandle (DevicePath, &Handle);
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = pBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, &BlockIo);
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = pBS->HandleProtocol (Handle, &gEfiDiskIoProtocolGuid, &DiskIo);
+
+ Status = pBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, &TcgProtocol);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = pBS->LocateProtocol (&gEfiTpmDeviceProtocolGuid, NULL, &TpmProtocol );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+
+ //
+ // Read the EFI Partition Table Header
+ //
+
+ Status = pBS->AllocatePool( EfiBootServicesData,
+ BlockIo->Media->BlockSize,
+ &PrimaryHeader );
+
+ if (PrimaryHeader == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = DiskIo->ReadDisk (
+ DiskIo,
+ BlockIo->Media->MediaId,
+ 1 * BlockIo->Media->BlockSize,
+ BlockIo->Media->BlockSize,
+ (UINT8 *)PrimaryHeader
+ );
+
+ if (EFI_ERROR (Status)) {
+ TRACE ((TRACE_ALWAYS, "Failed to Read Partition Table Header!\n"));
+ pBS->FreePool (PrimaryHeader);
+ return EFI_DEVICE_ERROR;
+ }
+ //
+ // Read the partition entry.
+ //
+ Status = pBS->AllocatePool( EfiBootServicesData,
+ PrimaryHeader->NumberOfPartitionEntries * PrimaryHeader->SizeOfPartitionEntry,
+ &EntryPtr );
+
+ if (EntryPtr == NULL) {
+ pBS->FreePool (PrimaryHeader);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = DiskIo->ReadDisk (
+ DiskIo,
+ BlockIo->Media->MediaId,
+ Mul64(PrimaryHeader->PartitionEntryLba, BlockIo->Media->BlockSize),
+ PrimaryHeader->NumberOfPartitionEntries * PrimaryHeader->SizeOfPartitionEntry,
+ EntryPtr);
+
+ if (EFI_ERROR (Status)) {
+ pBS->FreePool (PrimaryHeader);
+ pBS->FreePool (EntryPtr);
+ return EFI_DEVICE_ERROR;
+ }
+
+
+ //
+ // Count the valid partition
+ //
+ PartitionEntry = (TCG_EFI_PARTITION_ENTRY *)EntryPtr;
+ NumberOfPartition = 0;
+ for (Index = 0; Index < PrimaryHeader->NumberOfPartitionEntries; Index++) {
+ if (MemCmp(&PartitionEntry->PartitionTypeGuid, &NullGuid, sizeof(EFI_GUID))) {
+ NumberOfPartition++;
+ }
+ PartitionEntry++;
+ }
+ //
+ // Parepare Data for Measurement
+ //
+
+ //allocate memory for TCG event
+ Status = pBS->AllocatePool( EfiBootServicesData,
+ sizeof(TCG_PCR_EVENT_HDR) + \
+ (UINT32)(sizeof (TCG_EFI_PARTITION_TABLE_HEADER) + sizeof(UINTN)\
+ + (NumberOfPartition * PrimaryHeader->SizeOfPartitionEntry)),
+ &TcgEvent );
+
+ TcgEvent->PCRIndex = 5;
+ TcgEvent->EventType = EV_EFI_GPT_EVENT;
+ TcgEvent->EventSize = (UINT32)(sizeof (TCG_EFI_PARTITION_TABLE_HEADER) + sizeof(UINTN)\
+ + (NumberOfPartition * PrimaryHeader->SizeOfPartitionEntry));
+
+
+ Status = pBS->AllocatePool( EfiBootServicesData,
+ TcgEvent->EventSize,
+ &GptData );
+ if (GptData == NULL) {
+ pBS->FreePool (PrimaryHeader);
+ pBS->FreePool (EntryPtr);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ MemSet(GptData, TcgEvent->EventSize, 0);
+ //
+ // Copy the EFI_PARTITION_TABLE_HEADER and NumberOfPartition
+ //
+ MemCpy ((UINT8 *)GptData, (UINT8*)PrimaryHeader, sizeof (TCG_EFI_PARTITION_TABLE_HEADER));
+ GptData->NumberOfPartitions = NumberOfPartition;
+ //
+ // Copy the valid partition entry
+ //
+
+ PartitionEntry = (TCG_EFI_PARTITION_ENTRY*)EntryPtr;
+ GptIndex = 0;
+ for (Index = 0; Index < PrimaryHeader->NumberOfPartitionEntries; Index++) {
+ if (MemCmp (&PartitionEntry->PartitionTypeGuid, &NullGuid, sizeof(EFI_GUID))) {
+ MemCpy (
+ (UINT8 *)&GptData->Partitions + (GptIndex * sizeof (TCG_EFI_PARTITION_ENTRY)),
+ (UINT8 *)PartitionEntry,
+ sizeof (TCG_EFI_PARTITION_ENTRY)
+ );
+ GptIndex+=1;
+ }
+ PartitionEntry++;
+ }
+ //
+ // Measure the GPT data
+ //
+
+ pBS->CopyMem (TcgEvent->Event,
+ GptData,
+ TcgEvent->EventSize);
+
+ TpmProtocol ->Init( TpmProtocol );
+
+ Status = TcgProtocol->HashLogExtendEvent(
+ TcgProtocol,
+ (EFI_PHYSICAL_ADDRESS)GptData,
+ TcgEvent->EventSize,
+ TCG_ALG_SHA,
+ TcgEvent,
+ &evNum,
+ &Last);
+
+
+ TpmProtocol ->Close( TpmProtocol );
+
+ pBS->FreePool (PrimaryHeader);
+ pBS->FreePool (EntryPtr);
+ pBS->FreePool (TcgEvent);
+ pBS->FreePool (GptData);
+
+ TRACE(( TRACE_ALWAYS,"GPT_EXIT"));
+ return Status;
+}
+
+
+
+EFI_STATUS
+TcgMeasureAction(
+ IN CHAR8 *String
+ )
+{
+
+ TCG_PCR_EVENT *TcgEvent = NULL;
+ EFI_PHYSICAL_ADDRESS Last;
+ EFI_TCG_PROTOCOL *tcgSvc;
+ UINT32 evNum;
+ UINT32 Len;
+ EFI_STATUS Status;
+
+
+ Status = pBS->LocateProtocol (
+ &gEfiTcgProtocolGuid,
+ NULL,
+ &tcgSvc);
+
+ ASSERT(!EFI_ERROR(Status));
+
+ Len = (UINT32)Strlen(String);
+ Status = pBS->AllocatePool (EfiBootServicesData,
+ _TPM_STRUCT_PARTIAL_SIZE (TCG_PCR_EVENT, Event) +
+ Len,
+ &TcgEvent);
+
+ ASSERT(!EFI_ERROR(Status));
+
+ TcgEvent->PCRIndex = 5;
+ TcgEvent->EventType = EV_EFI_ACTION;
+ TcgEvent->EventSize = Len;
+
+ pBS->CopyMem (TcgEvent->Event,
+ String,
+ Len);
+
+ Status = tcgSvc->HashLogExtendEvent (
+ tcgSvc,
+ (EFI_PHYSICAL_ADDRESS)String,
+ TcgEvent->EventSize,
+ TCG_ALG_SHA,
+ TcgEvent,
+ &evNum,
+ &Last);
+
+ if(TcgEvent!=NULL)
+ {
+ pBS->FreePool (TcgEvent);
+ }
+
+ return Status;
+}
+
+UINT8 GetPlatformSupportType()
+{
+ return (AutoSupportType());
+}
+
+
+static EFI_TCG_PLATFORM_PROTOCOL mTcgPlatformProtocol = {
+ TcgMeasurePeImage,
+ TcgMeasureAction,
+ TcgMeasureGptTable
+};
+
+
+static AMI_TCG_PLATFORM_PROTOCOL mAmiTcgPlatformProtocol = {
+ GetPlatformSupportType
+};
+
+
+EFI_STATUS EFIAPI TcmDxeEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable);
+
+TpmDxeEntry(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE * SystemTable);
+
+
+
+EFI_STATUS
+EFIAPI TcgDxeEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable );
+
+EFI_STATUS
+EFIAPI Tcg20DxeEntry(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable );
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+// Procedure: CommonTcgDxEntryPoint
+//
+// Description: Common entry point for Tcgdxe
+//
+// Input: IN EFI_HANDLE ImageHandle
+// IN EFI_SYSTEM_TABLE *SystemTable
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI CommonTcgDxEntryPoint(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_STATUS Status;
+ TCG_PLATFORM_SETUP_PROTOCOL *ProtocolInstance;
+ EFI_GUID Policyguid = TCG_PLATFORM_SETUP_POLICY_GUID;
+ BOOLEAN TpmInitError = FALSE;
+#if TCG_LEGACY == 1
+ BOOLEAN TpmLegBin = TRUE;
+#else
+ BOOLEAN TpmLegBin = FALSE;
+#endif
+ TCG_CONFIGURATION Config;
+ EFI_TCG_PROTOCOL *TcgProtocol;
+ EFI_GUID TcgFirstbootGuid = AMI_TCG_RESETVAR_HOB_GUID;
+ void ** DummyPtr;
+ BOOLEAN *ResetAllTcgVar = NULL;
+
+
+ InitAmiLib( ImageHandle, SystemTable );
+
+ Status = pBS->LocateProtocol (&Policyguid, NULL, &ProtocolInstance);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ MemCpy(&Config, &ProtocolInstance->ConfigFlags, sizeof(TCG_CONFIGURATION));
+
+ Config.TcgSupportEnabled = 0;
+
+ if((AutoSupportType()== TRUE) || (TpmLegBin == TRUE))
+ {
+ if( Config.TpmSupport != 0x00)
+ {
+#if TCG_LEGACY == 0
+ Config.TcmSupport = TRUE;
+ Status = TcmDxeEntry( ImageHandle, SystemTable );
+#else
+ Config.TcmSupport = FALSE;
+ Status = TpmDxeEntry( ImageHandle, SystemTable);
+#endif
+ if(Status){
+ Config.TpmHardware = TRUE;
+ TpmInitError = TRUE;
+ }
+ }
+ }else{
+ Config.TcmSupport = FALSE;
+ Status = TpmDxeEntry( ImageHandle, SystemTable );
+ if(Status){
+ Config.TpmHardware = TRUE;
+ TpmInitError = TRUE;
+ }else{
+ Config.TpmHardware = FALSE; //negative logic False means present
+ }
+ }
+
+ if(TpmInitError){
+ Config.Tpm20Device = 0;
+ ProtocolInstance->UpdateStatusFlags(&Config, TRUE);
+ return Status;
+ }
+
+ Status = Tcg20DxeEntry( ImageHandle, SystemTable );
+ if(Status != EFI_UNSUPPORTED){
+ //all dependent components will depend on
+ //the TrEEProtocol installed above
+ return EFI_SUCCESS;
+ }
+
+ Status = TcgDxeEntry( ImageHandle, SystemTable );
+
+ if(EFI_ERROR(Status)){
+
+ //if Support was enabled don't change TPM state
+ if((ProtocolInstance->ConfigFlags.TcgSupportEnabled!=0 &&
+ ProtocolInstance->ConfigFlags.TpmSupport == 0) ||
+ (ProtocolInstance->ConfigFlags.TcgSupportEnabled!=0 &&
+ ProtocolInstance->ConfigFlags.TcmSupport == 0))
+ {
+ Config.TcgSupportEnabled = FALSE;
+ }
+ else{
+ Config.TpmEnable = 0;
+ Config.TpmOperation = 0;
+ Config.TpmEnaDisable = TRUE;
+ Config.TpmActDeact = TRUE;
+ Config.TpmOwnedUnowned = FALSE;
+ }
+
+ Config.PpiSetupSyncFlag = TRUE;
+ ProtocolInstance->UpdateStatusFlags(&Config, TRUE);
+ return Status;
+ }else{
+
+ Status = pBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, &TcgProtocol);
+ if (EFI_ERROR (Status)) {
+ Config.TcgSupportEnabled = FALSE;
+ ResetAllTcgVar = (UINT8*)LocateATcgHob(
+ pST->NumberOfTableEntries,
+ pST->ConfigurationTable,
+ &TcgFirstbootGuid);
+
+ DummyPtr = &ResetAllTcgVar;
+ if ( *DummyPtr != NULL )
+ {
+ if ( *ResetAllTcgVar == TRUE )
+ {
+ Config.PpiSetupSyncFlag = TRUE;
+ }
+ }
+
+ ProtocolInstance->UpdateStatusFlags(&Config, TRUE);
+ return Status;
+ }
+
+ Config.Tpm20Device = 0;
+ Config.TcgSupportEnabled = TRUE;
+ ProtocolInstance->UpdateStatusFlags(&Config, TRUE);
+ }
+
+ Status = pBS->InstallProtocolInterface(
+ &ImageHandle,
+ &gEfiTcgPrivateInterfaceGuid,
+ EFI_NATIVE_INTERFACE,
+ &mTcgPlatformProtocol);
+
+ Status = pBS->InstallProtocolInterface(
+ &ImageHandle,
+ &AmiTcgPlatformProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mAmiTcgPlatformProtocol);
+
+ return Status;
+}
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/xTcgPei.c b/Core/EM/TCG2/Common/xTcgPei.c
new file mode 100644
index 0000000..506f9be
--- /dev/null
+++ b/Core/EM/TCG2/Common/xTcgPei.c
@@ -0,0 +1,317 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/xTcgPei.c 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/xTcgPei.c $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 1:54p Fredericko
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 36 9/19/12 10:34a Fredericko
+// [TAG] EIP90807
+// [Category] Improvement
+// [Description] MonotonicCounter variable guid changed.
+// [Files] xTcgPei.c, AmiTcgPlatformPeiAfterMem.c
+//
+// 35 3/19/12 6:27p Fredericko
+// [TAG] EIP82769
+// [Description] Firmware updates disable the TPM when Firmware update
+// is done
+// [Files] TcgDxe.c, xTcgDxe.c, xTcgPei.c
+//
+// 34 12/12/11 3:17p Fredericko
+// [TAG] EIP76865
+// [Category] Improvement
+// [Description] Dual Support for TCM and TPM. System could hang in TXT
+// if txt is enabled in setup
+// [Files]
+// AmiTcgPlatfompeilib.c, AmiTcgPlatformPpi.cif, AmiTcgPlatformPpi.h,
+// AmiTcgPlatformProtocol.cif, AmiTcgPlatformProtocol.h,
+// EMpTcmPei.c, TcgDxe.cif, TcgPei.cif, TcgPeiAfterMem.cif,
+// TcgPeiAfterMem.mak, TcgTcmPeiAfterMem.c, xTcgDxe.c, xTcgPei.c,
+// xTcgPeiAfterMem.c
+//
+// 33 9/27/11 10:21p Fredericko
+// [TAG] EIP67286
+// [Category] Improvement
+// [Description] changes for Tcg Setup policy
+// [Files] Tcg.sdl
+// TcgPei.cif
+// TcgPei.mak
+// xtcgPei.c
+// xTcgPeiAfterMem.c
+// TcgPeiAfterMem.mak
+// TcgDxe.cif
+// TcgDxe.mak
+// xTcgDxe.c
+// AmiTcgPlatformPeilib.c
+// AmiTcgPlatformDxelib.c
+//
+// 32 4/27/11 3:01p Fredericko
+// removed VFR compile directive
+//
+// 31 3/29/11 12:57p Fredericko
+//
+// 30 3/28/11 2:14p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 29 5/19/10 5:53p Fredericko
+// Included File Header
+// Included File Revision History
+// Updated AMI Function Headers
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: xTcgPei.c
+//
+// Description:
+// Contians entry point function for TcgPei Subcomponent
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include <Pei.h>
+#include <TcgCommon.h>
+#include <AmiPeiLib.h>
+#include <TcgMisc.h>
+#include <ppi\AmiTcgPlatformPpi.h>
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+#include "PPI\CpuIo.h"
+#include "PPI\LoadFile.h"
+#include "TcgPlatformSetupPeiPolicy.h"
+#include "Tpm20Includes\Tpm20.h"
+#include "Tpm20CRBLib.h"
+
+
+
+EFI_GUID gTcgPpiGuid = PEI_TCG_PPI_GUID;
+EFI_GUID gPlatformGuid = AMI_TCG_PLATFORM_PPI_GUID;
+
+EFI_STATUS
+EFIAPI TpmPeiEntry (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices );
+
+EFI_STATUS
+EFIAPI TcmPeiEntry (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices );
+
+
+EFI_STATUS
+EFIAPI TcgPeiEntry (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices );
+
+EFI_STATUS
+EFIAPI TcgTcmPeiEntry (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices );
+
+EFI_STATUS TcgPeiBuildHobGuid(
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_GUID *Guid,
+ IN UINTN DataLength,
+ OUT VOID **Hob );
+
+EFI_STATUS
+EFIAPI Tpm20CrbEntry(
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices );
+
+UINT8 GetPlatformSupportType()
+{
+ return (AutoSupportType());
+}
+
+static AMI_TCG_PLATFORM_PPI PlatformTypePpi = {
+ GetPlatformSupportType
+};
+
+
+static EFI_PEI_PPI_DESCRIPTOR mPlatformPpiList[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPlatformGuid,
+ &PlatformTypePpi
+ }
+};
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: CommonTcgPeiEntryPoint
+//
+// Description: Entry point for Tcg PEI component
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI CommonTcgPeiEntryPoint(
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ EFI_STATUS Status;
+ VOID *Context = NULL;
+ BOOLEAN DeviceType = FALSE;
+ TCG_PLATFORM_SETUP_INTERFACE *TcgPeiPolicy = NULL;
+ EFI_GUID gTcgPeiPolicyGuid =\
+ TCG_PLATFORM_SETUP_PEI_POLICY_GUID;
+ TCG_CONFIGURATION ConfigFlags;
+ CHAR16 Monotonic[] = L"MonotonicCounter";
+#if defined(CORE_COMBINED_VERSION) && (CORE_COMBINED_VERSION > 262797)
+ EFI_GUID Guid = AMI_GLOBAL_VARIABLE_GUID;
+#else
+ EFI_GUID Guid = EFI_GLOBAL_VARIABLE;
+#endif
+ EFI_GUID TcgGuid = AMI_TCG_RESETVAR_HOB_GUID;
+ UINTN Size = sizeof(UINT32);
+ UINT32 Counter;
+ EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
+ EFI_HOB_GUID_TYPE *Hob;
+ BOOLEAN ResetAllTcgVar = FALSE;
+ EFI_GUID gTcgReadOnlyVariablePpiGuid
+ = EFI_TCG_PEI_READ_ONLY_VARIABLE_PPI_GUID;
+
+
+ Status = (*PeiServices)->InstallPpi( PeiServices, &mPlatformPpiList[0] );
+ if ( EFI_ERROR( Status ))
+ {
+ return EFI_UNLOAD_IMAGE;
+ }
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gTcgPeiPolicyGuid,
+ 0, NULL,
+ &TcgPeiPolicy);
+
+ if(EFI_ERROR(Status) || TcgPeiPolicy == NULL )return Status;
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gTcgReadOnlyVariablePpiGuid,
+ 0, NULL,
+ &ReadOnlyVariable
+ );
+
+ if(EFI_ERROR(Status) || ReadOnlyVariable == NULL )return Status;
+
+ Status = ReadOnlyVariable->GetVariable( PeiServices, Monotonic, &Guid,
+ NULL, &Size, &Counter );
+
+ if ( EFI_ERROR( Status ))
+ {
+
+ ResetAllTcgVar = TRUE;
+ Status = TcgPeiBuildHobGuid(
+ PeiServices,
+ &TcgGuid,
+ sizeof (BOOLEAN),
+ &Hob );
+
+ Hob++;
+ (*PeiServices)->CopyMem( Hob, &ResetAllTcgVar, sizeof (ResetAllTcgVar));
+ }
+
+ if(!AutoSupportType()){
+ Status = TpmPeiEntry( FfsHeader, PeiServices );
+ PEI_TRACE((-1, PeiServices, "TpmPeiEntry results = %r \n", Status));
+ if ( EFI_ERROR( Status )){
+ return Status;
+ }
+ }else{
+ Status = TcmPeiEntry( FfsHeader, PeiServices );
+ if ( EFI_ERROR( Status )){
+ return Status;}
+ }
+
+ PEI_TRACE((-1, PeiServices, "before getTcgPeiPolicy\n"));
+ Status = TcgPeiPolicy->getTcgPeiPolicy(PeiServices, &ConfigFlags);
+
+ PEI_TRACE((-1, PeiServices, "getTcgPeiPolicy results = %r \n", Status));
+
+ if ( ConfigFlags.TpmSupport == 0x00 || EFI_ERROR( Status ))
+ {
+ PEI_TRACE((-1, PeiServices, "ConfigFlags.TpmSupport == 0x00 || EFI_ERROR( Status )\n"));
+ return EFI_SUCCESS;
+ }
+
+
+ PEI_TRACE((-1, PeiServices, "TcgPeiEntry processing\n"));
+ if(!AutoSupportType()){
+ Status = TcgPeiEntry( FfsHeader, PeiServices );
+ PEI_TRACE((-1, PeiServices, "TcgPeiEntry result = %r\n", Status));
+ if(EFI_ERROR(Status)){
+ PEI_TRACE((-1, PeiServices, "Tpm20CrbEntry Execution\n", Status));
+ Tpm20CrbEntry(FfsHeader, PeiServices );
+ }
+ }else{
+ Status = TcgTcmPeiEntry( FfsHeader, PeiServices );
+ }
+
+ return Status;
+}
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Common/xTcgPeiAfterMem.c b/Core/EM/TCG2/Common/xTcgPeiAfterMem.c
new file mode 100644
index 0000000..772571c
--- /dev/null
+++ b/Core/EM/TCG2/Common/xTcgPeiAfterMem.c
@@ -0,0 +1,284 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPeiAfterMem/xTcgPeiAfterMem.c 1 4/21/14 2:16p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:16p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TcgPei/TcgPeiAfterMem/xTcgPeiAfterMem.c $
+//
+// 1 4/21/14 2:16p Fredericko
+//
+// 1 10/08/13 12:02p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:51p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 4 12/12/11 3:31p Fredericko
+// [TAG] EIP76865
+// [Category] Improvement
+// [Description] Dual Support for TCM and TPM. System could hang in TXT
+// if txt is enabled in setup
+// [Files] AmiTcgPlatfompeilib.c, AmiTcgPlatformPpi.cif,
+// AmiTcgPlatformPpi.h, AmiTcgPlatformProtocol.cif,
+// AmiTcgPlatformProtocol.h,
+// EMpTcmPei.c, TcgDxe.cif, TcgPei.cif, TcgPeiAfterMem.cif,
+// TcgPeiAfterMem.mak, TcgTcmPeiAfterMem.c, xTcgDxe.c, xTcgPei.c,
+// xTcgPeiAfterMem.c
+//
+// 3 9/27/11 10:22p Fredericko
+// [TAG] EIP67286
+// [Category] Improvement
+// [Description] changes for Tcg Setup policy
+//
+// [Files] Tcg.sdl
+// TcgPei.cif
+// TcgPei.mak
+// xtcgPei.c
+// xTcgPeiAfterMem.c
+// TcgPeiAfterMem.mak
+// TcgDxe.cif
+// TcgDxe.mak
+// xTcgDxe.c
+// AmiTcgPlatformPeilib.c
+// AmiTcgPlatformDxelib.c
+//
+// 2 9/03/11 8:04p Fredericko
+//
+// 1 8/22/11 1:45p Fredericko
+// [TAG] EIP61168
+// [Category] Improvement
+// [Description] Reload TCG PPI from memory when Memory is Installed
+// [Files] TcgPeiAfterMem.cif
+// TcgPeiAfterMem.c
+// xTcgPeiAfterMem.c
+// TcgPeiAfterMem.mak
+//
+// 32 4/27/11 3:01p Fredericko
+// removed VFR compile directive
+//
+// 31 3/29/11 12:57p Fredericko
+//
+// 30 3/28/11 2:14p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 29 5/19/10 5:53p Fredericko
+// Included File Header
+// Included File Revision History
+// Updated AMI Function Headers
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: xTcgPei.c
+//
+// Description:
+// Contians entry point function for TcgPei Subcomponent
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include <Pei.h>
+#include <TcgCommon.h>
+#include <AmiPeiLib.h>
+#include <TcgMisc.h>
+#include "PPI\TcgService\TcgService.h"
+#include "PPI\TpmDevice\TpmDevice.h"
+#include "PPI\CpuIo.h"
+#include <TpmLib.h>
+#include "PPI\LoadFile.h"
+#include "TcgPlatformSetupPeiPolicy.h"
+
+
+EFI_GUID gTcgPpiGuid = PEI_TCG_PPI_GUID;
+EFI_GUID gCacheInstallGuid = EFI_PEI_PERMANENT_MEMORY_INSTALLED_PPI;
+
+
+EFI_STATUS
+EFIAPI TcgPeiMemoryCallbackEntry(
+ IN EFI_PEI_SERVICES **PeiServices
+);
+
+EFI_STATUS
+EFIAPI TcgTcmPeiMemoryCallbackEntry(
+ IN EFI_PEI_SERVICES **PeiServices
+);
+
+
+typedef struct _TCG_PEI_MEMORY_CALLBACK
+{
+ EFI_PEI_NOTIFY_DESCRIPTOR NotifyDesc;
+ EFI_FFS_FILE_HEADER *FfsHeader;
+} TCG_PEI_MEMORY_CALLBACK;
+
+
+EFI_STATUS
+EFIAPI TcgPeiMemoryEntry(
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
+ IN VOID *Ppi );
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: OnMemoryDiscovered
+//
+// Description: Call Memory Present initialization on memory Installation
+//
+//
+// Input: IN EFI_PEI_SERVICES **PeiServices,
+// IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
+// IN VOID *Ppi
+//
+// Output: EFI STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI TcgPeiMemoryEntry(
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
+ IN VOID *Ppi )
+{
+ EFI_STATUS Status;
+ PEI_TCG_PPI *TcgPpi = NULL;
+
+ Status = (*PeiServices)->LocatePpi (
+ PeiServices,
+ &gTcgPpiGuid ,
+ 0,
+ NULL,
+ &TcgPpi);
+
+ if ( EFI_ERROR( Status )){
+ return Status;
+ }
+
+ if(AutoSupportType())
+ {
+ TcgTcmPeiMemoryCallbackEntry(PeiServices);
+ }else{
+ TcgPeiMemoryCallbackEntry(PeiServices);
+ }
+
+ return (Status);
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: CommonTcgPeiEntryPoint
+//
+// Description: Entry point for Tcg PEI component
+//
+//
+// Input: IN EFI_FFS_FILE_HEADER *FfsHeader
+// IN EFI_PEI_SERVICES **PeiServices,
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+EFIAPI ReInstallTcgServiceAfterMem(
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices )
+{
+ EFI_STATUS Status;
+ TCG_PLATFORM_SETUP_INTERFACE *TcgPeiPolicy = NULL;
+ EFI_GUID gTcgPeiPolicyGuid =\
+ TCG_PLATFORM_SETUP_PEI_POLICY_GUID;
+ TCG_PEI_MEMORY_CALLBACK *MemCallback;
+ TCG_CONFIGURATION ConfigFlags;
+
+ Status = IsTpmPresent((TPM_1_2_REGISTERS_PTR)(UINTN )PORT_TPM_IOMEMBASE);
+ if(EFI_ERROR(Status))return Status;
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices,
+ &gTcgPeiPolicyGuid,
+ 0, NULL,
+ &TcgPeiPolicy);
+
+ if(EFI_ERROR(Status))return Status;
+
+ Status = TcgPeiPolicy->getTcgPeiPolicy(PeiServices, &ConfigFlags);
+
+ if (ConfigFlags.TpmSupport == 0x00 || EFI_ERROR( Status ))
+ {
+ return EFI_SUCCESS;
+ }
+
+
+ Status = (**PeiServices).AllocatePool(
+ PeiServices,
+ sizeof (TCG_PEI_MEMORY_CALLBACK),
+ &MemCallback);
+
+ if ( !EFI_ERROR( Status ))
+ {
+ MemCallback->NotifyDesc.Flags
+ = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
+ | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
+ MemCallback->NotifyDesc.Guid = &gCacheInstallGuid;
+ MemCallback->NotifyDesc.Notify = TcgPeiMemoryEntry;
+ MemCallback->FfsHeader = FfsHeader;
+
+ Status = (*PeiServices)->NotifyPpi( PeiServices,
+ &MemCallback->NotifyDesc );
+ }
+
+ return Status;
+}
+
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.cif b/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.cif
new file mode 100644
index 0000000..697a7b6
--- /dev/null
+++ b/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.cif
@@ -0,0 +1,10 @@
+<component>
+ name = "ShaLib"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\CommonLibraries\ShaLib"
+ RefName = "ShaLib"
+[files]
+"ShaLib.sdl"
+"ShaLibPei.lib"
+"ShaLib.lib"
+<endComponent>
diff --git a/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.lib b/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.lib
new file mode 100644
index 0000000..651216b
--- /dev/null
+++ b/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.lib
Binary files differ
diff --git a/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.sdl b/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.sdl
new file mode 100644
index 0000000..6a6785f
--- /dev/null
+++ b/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLib.sdl
@@ -0,0 +1,27 @@
+TOKEN
+ Name = "ShaLib_SUPPORT"
+ Value = "1"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ Master = Yes
+ Token = "TCG2Support" "=" "1"
+End
+
+TOKEN
+ Name = "SHALIB"
+ Value = "$(SHALIB_DIR)\SHALIB.lib"
+ TokenType = "Expression"
+ TargetMAK = Yes
+End
+
+TOKEN
+ Name = "SHALIBPEI"
+ Value = "$(SHALIB_DIR)\SHALIBPEI.lib"
+ TokenType = "Expression"
+ TargetMAK = Yes
+End
+
+PATH
+ Name = "SHALIB_DIR"
+End \ No newline at end of file
diff --git a/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLibPei.lib b/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLibPei.lib
new file mode 100644
index 0000000..780b06b
--- /dev/null
+++ b/Core/EM/TCG2/CommonLibraries/ShaLib/ShaLibPei.lib
Binary files differ
diff --git a/Core/EM/TCG2/Libraries.cif b/Core/EM/TCG2/Libraries.cif
new file mode 100644
index 0000000..644e389
--- /dev/null
+++ b/Core/EM/TCG2/Libraries.cif
@@ -0,0 +1,10 @@
+<component>
+ name = "Libraries"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\"
+ RefName = "Libraries"
+[parts]
+"ShaLib"
+"TisLib"
+"Tpm20CRBLib"
+<endComponent>
diff --git a/Core/EM/TCG2/TCG2.chm b/Core/EM/TCG2/TCG2.chm
new file mode 100644
index 0000000..92c239a
--- /dev/null
+++ b/Core/EM/TCG2/TCG2.chm
Binary files differ
diff --git a/Core/EM/TCG2/Tcg.cif b/Core/EM/TCG2/Tcg.cif
new file mode 100644
index 0000000..f7a185d
--- /dev/null
+++ b/Core/EM/TCG2/Tcg.cif
@@ -0,0 +1,13 @@
+<component>
+ name = "TCG2"
+ category = eModule
+ LocalRoot = "Core\EM\TCG2\"
+ RefName = "TcgGeneric"
+[files]
+"TCG2.chm"
+"Tcg.sdl"
+[parts]
+"Libraries"
+"CommonHeaders"
+"Common"
+<endComponent>
diff --git a/Core/EM/TCG2/Tcg.sdl b/Core/EM/TCG2/Tcg.sdl
new file mode 100644
index 0000000..d925bfc
--- /dev/null
+++ b/Core/EM/TCG2/Tcg.sdl
@@ -0,0 +1,646 @@
+TOKEN
+ Name = "TCG2Support"
+ Value = "1"
+ Help = "Enable or Disable TCG_generic support"
+ TokenType = Boolean
+ TargetMAK = Yes
+ TargetH = Yes
+ Master = Yes
+End
+
+TOKEN
+ Name = "SecurityChipMode"
+ Value = "7"
+ Help = "4-bit Bit 0 Sets Discreet TPM 2.0, Bit 1 sets Ftpm, Bit 2 sets TPM 1.2, BIT3 reserved"
+ TokenType = Integer
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM12Enabled"
+ Value = "($(SecurityChipMode) & 0x4)"
+ Help = "TPM 1.2 Support Enabled"
+ TokenType = Integer
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM20Enabled"
+ Value = "($(SecurityChipMode) & 0x1)"
+ Help = "TPM 20 enabled"
+ TokenType = Integer
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "FTPM20Enabled"
+ Value = "($(SecurityChipMode) & 0x2)"
+ TokenType = Integer
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_SIZE"
+ Value = "010000h"
+ Help = "Size of Dxecore to measure"
+ TokenType = Integer
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_LEGACY"
+ Value = "0"
+ Help = "Main switch to enable Tcg Legacy support in Project."
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCGPPISPEC_1_2_SUPPORT"
+ Value = "1"
+ Help = "This will enable TCG Ppi spec 1.2 support. The default is 1.0 support since most O.S. will support released version 1.0."
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "USE_BIOS_IMAGE_AS_CRTM"
+ Value = "0"
+ Help = "Requires controlled access to BIOS region on the Flash PART. Easily achieved with secureboot."
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "WORD_ACCESS_SMI_PORT"
+ Value = "0"
+ Help = "This will cause 16 bit read and write to the TPM SMI port required for some AMD platforms"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "StartupCmd_SelfTest_State"
+ Value = "1"
+ Help = " 1 - Send TPM startup and Selftest before Mem. 0 Send selftest and Startup After Mem Init"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Token = "TCG_LEGACY" "=" "0"
+End
+
+TOKEN
+ Name = "StartupCmd_SelfTest_State"
+ Value = "0"
+ Help = "Always send selftest and Startup Command after Mem if TCG_LEGACY is enabled"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Lock = Yes
+ Token = "TCG_LEGACY" "=" "1"
+End
+
+TOKEN
+ Name = "TPM_DRIVER_WAIT"
+ Value = "005h"
+ Help = "Delay count for TPM wait loop. Default is 50us. Please dont change to less than 2 (4us)."
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "DELAY_AMOUNT"
+ Value = "010"
+ Help = "Delay amount for TPM wait loop. Default is 5us. Please dont change to less than 2 (2us)."
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "OVERRIDE_TCG_ASL"
+ Value = "0"
+ Help = "Allow override of TCG ASL files"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "Stack_Work_Around"
+ Value = "0"
+ Help = "Allows for working around binaries that don't return correctly when called into"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "PMBASE_RTC_WKAround"
+ Value = "1"
+ Help = "Calling into some TPM binaries via legacy IO might cause RTC status to be set."
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_DEBUG_MODE"
+ Value = "1"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+ Lock = Yes
+ Token = "DEBUG_MODE" "=" "1"
+ Token = "x64_BUILD" "=" "0"
+End
+
+TOKEN
+ Name = "SET_LIFETIME_PPLOCK"
+ Value = "0"
+ Help = "Main switch to set lifetime lock to TCG physical presence. Once set this is not revertible"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "USE_ZERO_SEPARATOR"
+ Value = "0"
+ Help = "Enable this bit to use a separator value of zeros"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPMID"
+ Value = "PNP0C31"
+ Help = "Device ID of the TPM device. This ID will show up in ACPI structure"
+ TokenType = Expression
+ TargetMAK = Yes
+ Token = "TCG_LEGACY" "=" "0"
+End
+
+TOKEN
+ Name = "CTPMID"
+ Value = "PNP0C31"
+ Help = "Compatible Device ID of the TPM device. This ID will show up in _CID object"
+ TokenType = Expression
+ TargetMAK = Yes
+ Token = "TCG_LEGACY" "=" "0"
+End
+
+TOKEN
+ Name = "CID_SUPPORT"
+ Value = "0"
+ Help = "Enable optional ACPI compatiblity support in TPM ASL"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM_IOMEMBASE"
+ Value = "0FED40000h"
+ Help = "Start of Mem I/O region dedicated for TPM access"
+ TokenType = Expression
+ TargetEQU = Yes
+ TargetMAK = Yes
+End
+
+TOKEN
+ Name = "PORT_TPM_IOMEMBASE"
+ Value = "0xFED40000h"
+ Help = "Start of Mem I/O region dedicated for TPM access"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_PCCLIENT_SPEC"
+ Value = "0"
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM_IOMEMSZ"
+ Value = "5000h"
+ Help = "Size of Mem I/O region dedicated for TPM access"
+ TokenType = Expression
+ TargetEQU = Yes
+ TargetMAK = Yes
+End
+
+TOKEN
+ Name = "TPM_IOBASE"
+ Value = "600h"
+ Help = "Define IOBase for Legacy support. Should not be zero if TCG_Legacy is enabled"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM_IOBASE_MAX"
+ Value = "6FFh"
+ Help = "Define IOBase for Legacy support. Should not be zero if TCG_Legacy is enabled"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM_IOBASE2"
+ Value = "7Eh"
+ Help = "I/O registers used to configure the TPM and programm to use\TPM_IOBASE I/O range"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM_IOBASE2_DATA"
+ Value = "7Fh"
+ Help = "I/O registers used to configure the TPM and programm to use\TPM_IOBASE I/O range"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM_IOSZ"
+ Value = "0FFh"
+ Help = "Size of the IO range with base TPM_IOBASE"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCGSMIPORT"
+ Value = "$(SW_SMI_IO_ADDRESS)"
+ Help = "IO port used to generate software SMI."
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCGSMIDATAPORT"
+ Value = "$(SW_SMI_IO_ADDRESS)+1"
+ Help = "IO port used to generate software SMI."
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "PPI_OFFSET"
+ Value = "035h"
+ Help = "Ppi SMI Value"
+ TokenType = Integer
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "SMIA"
+ Value = "$(TCGSMIPORT)"
+ Help = "Add a name of smiport for asl using"
+ TokenType = Integer
+ TargetASL = Yes
+End
+
+TOKEN
+ Name = "SMIB"
+ Value = "$(TCGSMIDATAPORT)"
+ Help = "Add a name of smiport for asl using"
+ TokenType = Integer
+ TargetASL = Yes
+End
+
+TOKEN
+ Name = "OFST"
+ Value = "$(PPI_OFFSET)"
+ Help = "Add a name of smiport for asl using"
+ TokenType = Integer
+ TargetASL = Yes
+End
+
+TOKEN
+ Name = "PARTIALLY_MEASURE_FVMAIN"
+ Value = "0"
+ Help = "Enable this token to make the TPM measure part of FVMAIN. This is useful to reduce the amount of time used for hashing FVMAIN."
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_FV_MAIN_SIZE"
+ Value = "0x180000"
+ Help = "Size of FV_MAIN to Measure."
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Token = "PARTIALLY_MEASURE_FVMAIN" "=" "1"
+End
+
+TOKEN
+ Name = "TCG_CONVENTIONAL_BIOS_6_1"
+ Value = "1"
+ Help = "Enable this token to send the TcgStartup_DISABLE commmand if Bootmode is recovery"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_MOR"
+ Value = "1"
+ TokenType = Boolean
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TPM_PASSWORD_AUTHENTICATION"
+ Value = "0"
+ Help = "1 - If a pasword is set, it will be required for TPM state change. 0 - No password reqired."
+ TokenType = Boolean
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "CONFIRM_SETUP_CHANGE"
+ Value = "0"
+ Help = "1 - A Setup change to TPM State requires confirmation (same as OS change). 0 - Setup change not confirmed."
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "LOG_EV_EFI_ACTION"
+ Value = "0"
+ Help = "Switch to LOG TPM events of type EV_ACTION"
+ TokenType = Boolean
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_CLEAR_REQUEST_KEY"
+ Value = "SCAN_F12"
+ Help = "Set to one of the defined constants from EFI_SIMPLE_TEXT_INPUT protocol. When you change the Key, Change the message string in the tcgstring.uni"
+ TokenType = Expression
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_CONFIGURATION_ACCEPT_KEY"
+ Value = "SCAN_F10"
+ Help = "Set to one of the defined constants from EFI_SIMPLE_TEXT_INPUT protocol. When you change the Key, Change the message string in the tcgstring.uni"
+ TokenType = Expression
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_CONFIGURATION_IGNORE_KEY"
+ Value = "SCAN_ESC"
+ Help = "Set to one of the defined constants from EFI_SIMPLE_TEXT_INPUT protocol. When you change the Key, Change the message string in the tcgstring.uni"
+ TokenType = Expression
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "DSDT_GUID"
+ Value = "{0x11D8AC35,0xFB8A,0x44d1,0x8D,0x09,0x0B,0x56,0x06,0xD3,0x21,0xB9}"
+ Help = "GUID for DSDT..PORTING...VERIFY VALUE MATCHES WITH ACTUAL DSDT_GUID"
+ TokenType = Expression
+ TargetH = Yes
+ Range = "GUID"
+End
+
+TOKEN
+ Name = "MEMORY_ONLY_RESET_CONTROL_GUID"
+ Value = "{0xe20939be, 0x32d4, 0x41be, 0xa1, 0x50, 0x89, 0x7f, 0x85, 0xd4, 0x98, 0x29}"
+ Help = "Industry standard guid for MOR"
+ TokenType = Expression
+ TargetH = Yes
+ Range = "GUID"
+End
+
+TOKEN
+ Name = "CRTM_GUID"
+ Value = "{0x546BFB1E,0x1D0C,0x4055,0xA4,0xAD,0x4E,0xF4,0xBF,0x17,0xB8,0x3A}"
+ Help = "GUID for CRTM..PORTING..."
+ TokenType = Expression
+ TargetH = Yes
+ Range = "GUID"
+End
+
+TOKEN
+ Name = "AMI_OS_PPI_CONFIRMATION_OVERRIDE_GUID"
+ Value = "{0x5f171f5f, 0x8385, 0x4086, 0xa6, 0x9b, 0x1f, 0xcf, 0x6, 0xae, 0x4a, 0x3d}"
+ Help = "GUID for Overriding TCG Physical Presence Locking"
+ TokenType = Expression
+ TargetH = Yes
+ Range = "GUID"
+End
+
+TOKEN
+ Name = "AMI_BIOSPPI_FLAGS_MANAGEMENT_GUID"
+ Value = "{0xe9008d70, 0x2a4e, 0x47ea, 0x8e, 0xc4, 0x72, 0xe2, 0x57, 0x67, 0xe5, 0xef}"
+ Help = "GUID for OEM protocol to reading persistent BIOS TPM Management flags. See Ppi section 2 table 1"
+ TokenType = Expression
+ TargetH = Yes
+ Range = "GUID"
+End
+
+TOKEN
+ Name = "TRST"
+ Value = "2"
+ Help = "Platform transition for PPI request under O.S. 0: None 1: Shutdown 2: Reboot 3: OS Vendor Specific"
+ TokenType = Integer
+ TargetASL = Yes
+ TargetH = Yes
+ Range = "0 - 4"
+End
+
+TOKEN
+ Name = "TCG_PLATFORM_CLASS"
+ Value = "0"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_BIOS_TYPE_INTERFACE"
+ Value = "3"
+ TokenType = Integer
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_BIOS_TYPE_MAPPING"
+ Value = "2"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_SPEC_VERSION_MAJOR"
+ Value = "1"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_SPEC_VERSION_MINOR"
+ Value = "2"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TCG_SPEC_ERRATA"
+ Value = "1"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "AUTO_ACCEPT_PPI"
+ Value = "1"
+ Help = "Use this token for PreProduction WHCK TESTING. If Enabled PPi Requests will be automatically executed without use interaction"
+ TokenType = Boolean
+ TargetH = Yes
+END
+
+TOKEN
+ Name = "TCMF"
+ Value = "0"
+ Help = "TPM ASL update Variable"
+ TokenType = Integer
+ TargetASL = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TMF1"
+ Value = "0"
+ Help = "TPM ASL update Variable"
+ TokenType = Integer
+ TargetASL = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TMF2"
+ Value = "0"
+ Help = "TPM ASL update Variable"
+ TokenType = Integer
+ TargetASL = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TMF3"
+ Value = "0"
+ Help = "TPM ASL update Variable"
+ TokenType = Integer
+ TargetASL = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "tcgLibLite"
+ Value = "$(BUILD_DIR)\tcgLibLite.lib"
+ TokenType = Expression
+ TargetMAK = Yes
+End
+
+TOKEN
+ Name = "TTPF"
+ Value = "1"
+ TokenType = Integer
+ TargetASL = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "TTDP"
+ Value = "0"
+ TokenType = Integer
+ TargetASL = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "PTTHciSmm_SUPPORT"
+ Value = "0"
+ Help = " 1 - Send TPM startup and Selftest before Mem. 0 Send selftest and Startup After Mem Init"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+End
+
+PATH
+ Name = "TCG_DIR"
+ Help = "Tcg Directory"
+End
+
+ELINK
+ Name = "PasswordAuthentication,"
+ Parent = "MinisetupDriverEntryHook,"
+ Token = "TPM_PASSWORD_AUTHENTICATION" "=" "1"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "/D PTT_FLAG"
+ Parent = "GLOBAL_DEFINES"
+ InvokeOrder = AfterParent
+End
+
diff --git a/Core/EM/TCG2/TisLib/INTTcgAcpi.h b/Core/EM/TCG2/TisLib/INTTcgAcpi.h
new file mode 100644
index 0000000..6ebcdc2
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/INTTcgAcpi.h
@@ -0,0 +1,114 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/INTTcgAcpi.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/INTTcgAcpi.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 2 5/19/10 5:24p Fredericko
+// Included File Header
+// Included File Revision History
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: INTTcgAcpi.h
+//
+// Description: Acpi definitions for TCG module
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCG_ACPI_3_0_H_
+#define _TCG_ACPI_3_0_H_
+
+
+#define EFI_ACPI_30_TABLE_GUID EFI_ACPI_20_TABLE_GUID
+
+extern EFI_GUID gEfiAcpiTableGuid;
+extern EFI_GUID gEfiAcpi20TableGuid;
+extern EFI_GUID gEfiAcpi30TableGuid;
+
+
+#pragma pack(1)
+
+typedef struct
+{
+ UINT32 Signature;
+ UINT32 Length;
+ UINT8 Revision;
+ UINT8 Checksum;
+ UINT8 OemId[6];
+ UINT64 OemTableId;
+ UINT32 OemRevision;
+ UINT32 CreatorId;
+ UINT32 CreatorRevision;
+} EFI_ACPI_DESCRIPTION_HEADER;
+
+
+//
+// "TCPA" Trusted Computing Platform Alliance Capabilities Table
+//
+#define\
+ EFI_ACPI_3_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE \
+ 0x41504354
+
+
+#pragma pack()
+
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
diff --git a/Core/EM/TCG2/TisLib/TcgCommon.c b/Core/EM/TCG2/TisLib/TcgCommon.c
new file mode 100644
index 0000000..922514a
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TcgCommon.c
@@ -0,0 +1,808 @@
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgCommon.c 1 4/21/14 2:14p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:14p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgCommon.c $
+//
+// 1 4/21/14 2:14p Fredericko
+//
+// 3 3/17/14 3:04p Fredericko
+//
+// 2 3/11/14 6:00p Fredericko
+// [TAG] EIP151925
+// [Category] New Feature
+// [Description] Changes for TcgGeneric Regression Testing
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 12:34p Fredericko
+// Sha256 support policy update
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 9 3/19/12 6:13p Fredericko
+//
+// 8 3/29/11 12:24p Fredericko
+//
+// 7 3/28/11 12:12p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 6 5/19/10 5:07p Fredericko
+// Included File Header
+// Included File Revision History
+// Include \Updated AMI Function Headers
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TcgCommon.c
+
+ Abstract:
+
+ TCG Commands implemented for both PEI and DXE
+
+ --*/
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgCommon.c
+//
+// Description:
+// common TCG functions can be found here
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include "TcgCommon.h"
+#include <AmiDxeLib.h>
+#include "token.h"
+#include "Sha.h"
+
+#define TCG_EFI_HOB_LIST_GUID \
+ { 0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d}
+
+#pragma pack (1)
+typedef struct _TCG_PCR_EVENT_HDR2 {
+ TCG_PCRINDEX PCRIndex;
+ TCG_EVENTTYPE EventType;
+} TCG_PCR_EVENT_HDR2;
+#pragma pack()
+
+UINT16
+__stdcall TcgCommonH2NS(
+ IN UINT16 Val )
+{
+ return TPM_H2NS( Val );
+}
+
+UINT32
+__stdcall TcgCommonH2NL(
+ IN UINT32 Val )
+{
+ return TPM_H2NL( Val );
+}
+
+
+
+VOID
+__stdcall TcgCommonCopyMem(
+ IN VOID *CallbackContext,
+ OUT VOID *Dest,
+ IN VOID *Src,
+ IN UINTN Size )
+{
+ CHAR8 *Destination8;
+ CHAR8 *Source8;
+
+ if ( Src < Dest )
+ {
+ Destination8 = (CHAR8*) Dest + Size - 1;
+ Source8 = (CHAR8*) Src + Size - 1;
+ while ( Size-- )
+ {
+ *(Destination8--) = *(Source8--);
+ }
+ }
+ else {
+ Destination8 = (CHAR8*) Dest;
+ Source8 = (CHAR8*) Src;
+ while ( Size-- )
+ {
+ *(Destination8++) = *(Source8++);
+ }
+ }
+}
+
+
+#pragma optimize("",off)
+UINTN FindNextLogLocation(TCG_PCR_EVENT_HDR *TcgLog, UINTN EventNum)
+{
+ TCG_PCR_EVENT_HDR2 *TcgLogNext = (TCG_PCR_EVENT_HDR2 *)TcgLog;
+ UINTN NextLoc =0;
+ UINT32 EventSize=0;
+ UINTN i=0;
+
+ if(EventNum == 0) return ((UINTN) TcgLogNext);
+ //return the location of the next log
+ for(i=0;i<EventNum;i++){
+ if(TcgLogNext == NULL)break;
+ if(TcgLogNext->PCRIndex > 24 || TcgLogNext->PCRIndex < 0)
+ break;
+
+ EventSize = *(UINT32 *)(((UINTN)TcgLogNext) + TPM_SHA1_160_HASH_LEN + sizeof(TCG_PCR_EVENT_HDR2));
+ NextLoc = (UINTN)(((UINTN)TcgLogNext)+ EventSize + sizeof(EventSize)+\
+ + TPM_SHA1_160_HASH_LEN + sizeof(TCG_PCR_EVENT_HDR2));
+
+ TcgLogNext = (TCG_PCR_EVENT_HDR2 *)NextLoc;
+ }
+ return ((UINTN) TcgLogNext);
+}
+#pragma optimize("",on)
+
+
+EFI_STATUS
+__stdcall TcgCommonLogEvent(
+ IN VOID *CallbackContext,
+ IN TCG_PCR_EVENT *EvtLog,
+ IN OUT UINT32 *TableSize,
+ IN UINT32 MaxSize,
+ IN TCG_PCR_EVENT *NewEntry,
+ IN UINT8 HashAlgorithm )
+{
+ UINT32 TempSize;
+
+ TempSize = sizeof(TCG_PCR_EVENT)-sizeof(NewEntry->Digest) - sizeof(UINT32)-1;
+ TcgCommonCopyMem( CallbackContext, EvtLog, NewEntry, TempSize );
+
+ if(HashAlgorithm == 0){
+ TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), (UINT8 *)&NewEntry->Digest.digest, sizeof(NewEntry->Digest.digest) );
+ TempSize+=sizeof(NewEntry->Digest.digest);
+ TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), (UINT8 *)&NewEntry->EventSize, sizeof(UINT32));
+ TempSize+=sizeof(UINT32);
+ TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), NewEntry->Event, NewEntry->EventSize);
+ }
+ *TableSize += (TempSize + NewEntry->EventSize);
+ return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+__stdcall TcmCommonLogEvent(
+ IN VOID *CallbackContext,
+ IN TCM_PCR_EVENT *EvtLog,
+ IN OUT UINT32 *TableSize,
+ IN UINT32 MaxSize,
+ IN TCM_PCR_EVENT *NewEntry )
+{
+ UINT32 EvtSize;
+
+ EvtSize = NewEntry->EventSize + sizeof (*NewEntry) - 1;
+
+ if ( *TableSize + EvtSize > MaxSize )
+ {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ EvtLog = (TCM_PCR_EVENT*)((UINT8*)EvtLog + *TableSize);
+ TcgCommonCopyMem( CallbackContext, EvtLog, NewEntry, EvtSize );
+
+ *TableSize += EvtSize;
+ return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+__stdcall TcgCommonSha1Start(
+ IN VOID *CallbackContext,
+ IN TCG_ALGORITHM_ID AlgId,
+ OUT UINT32 *MaxBytes )
+{
+ EFI_STATUS Status;
+ TPM_1_2_CMD_HEADER cmdSHA1Start = {
+ TPM_H2NS( TPM_TAG_RQU_COMMAND ),
+ TPM_H2NL( sizeof (TPM_1_2_CMD_HEADER)),
+ TPM_H2NL( TPM_ORD_SHA1Start )
+ };
+ TPM_1_2_RET_SHA1START retSHA1Start;
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+
+ if ( AlgId != TCG_ALG_SHA )
+ {
+ return EFI_UNSUPPORTED;
+ }
+
+ if(AutoSupportType()){
+ cmdSHA1Start.Ordinal = TPM_H2NL(TCM_ORD_SHA1Start);
+ }
+
+
+ InBuffer[0].Buffer = &cmdSHA1Start;
+ InBuffer[0].Size = sizeof (cmdSHA1Start);
+ OutBuffer[0].Buffer = &retSHA1Start;
+ OutBuffer[0].Size = sizeof (retSHA1Start);
+ Status = TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer );
+
+ if ( EFI_ERROR( Status ) || retSHA1Start.Header.RetCode != 0 )
+ {
+ return Status;
+ }
+
+ if ( MaxBytes != NULL )
+ {
+ *MaxBytes = TcgCommonN2HL( retSHA1Start.MaxBytes );
+ }
+ return EFI_SUCCESS;
+}
+
+
+
+EFI_STATUS
+__stdcall TcgCommonSha1Update(
+ IN VOID *CallbackContext,
+ IN VOID *Data,
+ IN UINT32 DataLen,
+ IN UINT32 MaxBytes )
+{
+ EFI_STATUS Status;
+ TPM_1_2_CMD_SHA1UPDATE cmdSHA1Update;
+ TPM_1_2_RET_HEADER retSHA1Update;
+ TPM_TRANSMIT_BUFFER InBuffer[2], OutBuffer[1];
+ UINT8 *DataPtr;
+
+ if ( DataLen < 64 )
+ {
+ return EFI_SUCCESS;
+ }
+
+ cmdSHA1Update.Header.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdSHA1Update.Header.Ordinal = TPM_H2NL( TPM_ORD_SHA1Update );
+
+ if(AutoSupportType()){
+ cmdSHA1Update.Header.Ordinal = TPM_H2NL(TCM_ORD_SHA1Update);
+ }
+
+ InBuffer[0].Buffer = &cmdSHA1Update;
+ InBuffer[0].Size = sizeof (cmdSHA1Update);
+ OutBuffer[0].Buffer = &retSHA1Update;
+ OutBuffer[0].Size = sizeof (retSHA1Update);
+
+ DataPtr = (UINT8*)Data;
+
+ do
+ {
+ InBuffer[1].Buffer = DataPtr;
+ InBuffer[1].Size = DataLen < MaxBytes ? DataLen : MaxBytes;
+
+ cmdSHA1Update.NumBytes = TcgCommonH2NL((UINT32)InBuffer[1].Size );
+ cmdSHA1Update.Header.ParamSize = TcgCommonH2NL(
+ (UINT32)InBuffer[1].Size + sizeof (cmdSHA1Update)
+ );
+
+ DataPtr += InBuffer[1].Size;
+ DataLen -= (UINT32)InBuffer[1].Size;
+
+ Status = TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer );
+ } while ( !EFI_ERROR( Status ) && DataLen >= 64 );
+
+ return Status;
+}
+
+
+
+EFI_STATUS
+__stdcall TcgCommonSha1CompleteExtend(
+ IN VOID *CallbackContext,
+ IN VOID *Data,
+ IN UINT32 DataLen,
+ IN TPM_PCRINDEX PCRIndex,
+ OUT TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue )
+{
+ TPM_1_2_CMD_SHA1COMPLETEEXTEND cmdSHA1Complete;
+ TPM_1_2_RET_HEADER retSHA1Complete;
+ TPM_TRANSMIT_BUFFER InBuffer[2], OutBuffer[3];
+
+ if ( DataLen >= 64 )
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ cmdSHA1Complete.Header.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdSHA1Complete.Header.ParamSize = TcgCommonH2NL(sizeof(cmdSHA1Complete)
+ + DataLen);
+ cmdSHA1Complete.Header.Ordinal = TPM_H2NL( TPM_ORD_SHA1CompleteExtend );
+
+ if(AutoSupportType()){
+ cmdSHA1Complete.Header.Ordinal = TPM_H2NL(TCM_ORD_SHA1CompleteExtend);
+ }
+
+ cmdSHA1Complete.PCRIndex = TcgCommonH2NL( PCRIndex );
+ cmdSHA1Complete.NumBytes = TcgCommonH2NL( DataLen );
+
+ InBuffer[0].Buffer = &cmdSHA1Complete;
+ InBuffer[0].Size = sizeof (cmdSHA1Complete);
+ InBuffer[1].Buffer = Data;
+ InBuffer[1].Size = DataLen;
+
+ OutBuffer[0].Buffer = &retSHA1Complete;
+ OutBuffer[0].Size = sizeof (retSHA1Complete);
+ OutBuffer[1].Buffer = Digest;
+ OutBuffer[1].Size = sizeof (*Digest);
+ OutBuffer[2].Buffer = NewPCRValue;
+ OutBuffer[2].Size = sizeof (*NewPCRValue);
+
+ return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer );
+}
+
+
+EFI_STATUS
+__stdcall TcmCommonSha1CompleteExtend(
+ IN VOID *CallbackContext,
+ IN VOID *Data,
+ IN UINT32 DataLen,
+ IN TPM_PCRINDEX PCRIndex,
+ OUT TCM_DIGEST *Digest,
+ OUT TCM_DIGEST *NewPCRValue )
+{
+ TPM_1_2_CMD_SHA1COMPLETEEXTEND cmdSHA1Complete;
+ TPM_1_2_RET_HEADER retSHA1Complete;
+ TPM_TRANSMIT_BUFFER InBuffer[2], OutBuffer[3];
+
+ if ( DataLen >= 64 )
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ cmdSHA1Complete.Header.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdSHA1Complete.Header.ParamSize = TcgCommonH2NL(sizeof(cmdSHA1Complete)
+ + DataLen);
+ cmdSHA1Complete.Header.Ordinal = TPM_H2NL( TPM_ORD_SHA1CompleteExtend );
+
+ if(AutoSupportType()){
+ cmdSHA1Complete.Header.Ordinal = TPM_H2NL(TCM_ORD_SHA1CompleteExtend);
+ }
+
+ cmdSHA1Complete.PCRIndex = TcgCommonH2NL( PCRIndex );
+ cmdSHA1Complete.NumBytes = TcgCommonH2NL( DataLen );
+
+ InBuffer[0].Buffer = &cmdSHA1Complete;
+ InBuffer[0].Size = sizeof (cmdSHA1Complete);
+ InBuffer[1].Buffer = Data;
+ InBuffer[1].Size = DataLen;
+
+ OutBuffer[0].Buffer = &retSHA1Complete;
+ OutBuffer[0].Size = sizeof (retSHA1Complete);
+ OutBuffer[1].Buffer = Digest;
+ OutBuffer[1].Size = sizeof (*Digest);
+ OutBuffer[2].Buffer = NewPCRValue;
+ OutBuffer[2].Size = sizeof (*NewPCRValue);
+
+ return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer );
+}
+
+
+
+EFI_STATUS
+__stdcall TcmCommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PCRIndex,
+ IN TCM_DIGEST *Digest,
+ OUT TCM_DIGEST *NewPCRValue )
+{
+ TPM_1_2_CMD_HEADER cmdHeader;
+ TPM_1_2_RET_HEADER retHeader;
+ TPM_TRANSMIT_BUFFER InBuffer[3], OutBuffer[2];
+
+ InBuffer[0].Buffer = &cmdHeader;
+ InBuffer[0].Size = sizeof (cmdHeader);
+ InBuffer[1].Buffer = &PCRIndex;
+ InBuffer[1].Size = sizeof (PCRIndex);
+ InBuffer[2].Buffer = Digest->digest;
+ InBuffer[2].Size = sizeof (Digest->digest);
+
+ OutBuffer[0].Buffer = &retHeader;
+ OutBuffer[0].Size = sizeof (retHeader);
+ OutBuffer[1].Buffer = NewPCRValue->digest;
+ OutBuffer[1].Size = sizeof (NewPCRValue->digest);
+
+ cmdHeader.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdHeader.ParamSize = TPM_H2NL(sizeof (cmdHeader)
+ + sizeof (PCRIndex) + sizeof (Digest->digest));
+
+ cmdHeader.Ordinal = TPM_H2NL( TCM_ORD_Extend );
+ PCRIndex = TcgCommonH2NL( PCRIndex );
+
+ return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer );
+}
+
+
+EFI_STATUS
+__stdcall Tcg20CommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PcrIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue,
+ IN UINT8 DigestSize )
+{
+ TPM2_PCRExtend_cmd_t Cmd;
+ TPM2_PCRExtend_res_t Res;
+ TPM2_PCRExtend_res_t Tmpres;
+ UINT32 CmdSize;
+ UINT8 *Buffer;
+ UINT8 *AuthSizeOffset;
+ UINT8 *ResultBuf = NULL;
+ UINT32 ResultBufSize = 0;
+
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+
+ Cmd.Tag = (TPMI_ST_COMMAND_TAG)TPM_H2NS(TPM_ST_SESSIONS);
+ Cmd.CommandSize = TPM_H2NL(sizeof(Cmd));
+ Cmd.CommandCode = TPM_H2NL(TPM_CC_PCR_Extend);
+
+ Buffer = (UINT8 *)&Cmd.inputParameters;
+ *(UINT32 *)Buffer = TPM_H2NL(PcrIndex);
+ Buffer += sizeof(UINT32);
+
+ AuthSizeOffset = Buffer;
+ *(UINT32 *)Buffer = 0;
+ Buffer += sizeof(UINT32);
+
+ // pcr authHandle
+ *(UINT32 *)Buffer = TPM_H2NL(TPM_RS_PW);
+ Buffer += sizeof(UINT32);
+
+ // nonce = nullNonce
+ *(UINT16 *)Buffer = 0;
+ Buffer += sizeof(UINT16);
+
+ // sessionAttributes = 0
+ *(UINT8 *)Buffer = 0;
+ Buffer += sizeof(UINT8);
+
+ // auth = nullAuth
+ *(UINT16 *)Buffer = 0;
+ Buffer += sizeof(UINT16);
+
+ // authorizationSize
+ *(UINT32 *)AuthSizeOffset = TPM_H2NL((UINT32)(Buffer - AuthSizeOffset - sizeof(UINT32)));
+
+ //Digest count
+ *(UINT32 *)Buffer = TPM_H2NL(1);
+ Buffer += sizeof(UINT32);
+
+ //Hash alg
+ *(UINT16 *)Buffer = TPM_H2NS(TPM2_ALG_SHA1);
+ Buffer += sizeof(UINT16);
+
+ // Get the digest size based on Hash Alg
+ TcgCommonCopyMem(CallbackContext, Buffer, &Digest->digest, DigestSize);
+
+ Buffer += DigestSize;
+
+ CmdSize = (UINT32)(Buffer - (UINT8 *)&Cmd);
+ Cmd.CommandSize = TPM_H2NL(CmdSize);
+
+ ResultBuf = (UINT8 *) &Tmpres;
+ ResultBufSize = sizeof(Res);
+
+ InBuffer[0].Buffer = &Cmd;
+ InBuffer[0].Size = CmdSize;
+ OutBuffer[0].Buffer = ResultBuf;
+ OutBuffer[0].Size = ResultBufSize;
+
+ return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer );
+
+}
+
+
+
+
+EFI_STATUS
+__stdcall SHA1HashAll(
+ IN VOID *CallbackContext,
+ IN VOID *HashData,
+ IN UINTN HashDataLen,
+ OUT TCG_DIGEST *Digest
+)
+{
+ SHA1_CTX Sha1Ctx;
+ unsigned char DigestArray[20];
+
+ SHA1Init( &Sha1Ctx );
+
+ SHA1Update( &Sha1Ctx, HashData, (u32)HashDataLen );
+
+ SHA1Final( DigestArray, &Sha1Ctx );
+
+ TcgCommonCopyMem(
+ CallbackContext,
+ Digest->digest,
+ DigestArray,
+ sizeof (Digest->digest));
+
+ return EFI_SUCCESS;
+}
+
+
+/*
+EFI_STATUS
+__stdcall SHA2HashAll(
+ IN VOID *CallbackContext,
+ IN VOID *HashData,
+ IN UINTN HashDataLen,
+ OUT TCG_DIGEST *Digest
+)
+{
+ SHA2_CTX Sha2Ctx;
+ unsigned char DigestArray[32];
+
+ sha256_init( &Sha2Ctx );
+
+ sha256_process( &Sha2Ctx, HashData, (u32)HashDataLen );
+
+ sha256_done( &Sha2Ctx, DigestArray );
+
+ TcgCommonCopyMem(
+ CallbackContext,
+ Digest->digestSha2,
+ DigestArray,
+ sizeof (Digest->digestSha2));
+
+ return EFI_SUCCESS;
+}*/
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: GetHob
+//
+// Description: Find instance of a HOB type in a HOB list
+//
+// Input:
+// Type The HOB type to return.
+// HobStart The first HOB in the HOB list.
+//
+// Output:
+// Pointer to the Hob matching the type or NULL
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+VOID* GetHob(
+ IN UINT16 Type,
+ IN VOID *HobStart )
+{
+ EFI_PEI_HOB_POINTERS Hob;
+
+ Hob.Raw = HobStart;
+
+ //
+ // Return input if not found
+ //
+ if ( HobStart == NULL )
+ {
+ return HobStart;
+ }
+
+ //
+ // Parse the HOB list, stop if end of list or matching type found.
+ //
+ while ( !END_OF_HOB_LIST( Hob ))
+ {
+ if ( Hob.Header->HobType == Type )
+ {
+ break;
+ }
+
+ Hob.Raw = GET_NEXT_HOB( Hob );
+ }
+
+ //
+ // Return input if not found
+ //
+ if ( END_OF_HOB_LIST( Hob ))
+ {
+ return HobStart;
+ }
+
+ return (VOID*)(Hob.Raw);
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: CompareGuid
+//
+// Description: Compares two input GUIDs
+//
+// Input: Comparision status
+//
+// Output: None
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+BOOLEAN CompareGuid(
+ EFI_GUID *G1,
+ EFI_GUID *G2 )
+{
+ UINT32 *p1 = (UINT32*)G1, *p2 = (UINT32*)G2;
+ UINTN i;
+
+ for ( i = 0; i < 4; ++i )
+ {
+ if ( p1[i] != p2[i] )
+ {
+ return FALSE;
+ }
+ }
+ return TRUE;
+ ;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: LocateATcgHob
+//
+// Description:
+//
+// Input:
+//
+// Output: None
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_GUID gEfiAmiTHobListGuid = TCG_EFI_HOB_LIST_GUID;
+VOID* LocateATcgHob(
+ UINTN NoTableEntries,
+ EFI_CONFIGURATION_TABLE *ConfigTable,
+ EFI_GUID *HOB_guid )
+{
+ VOID *HobStart;
+ VOID *PtrHob;
+
+ while ( NoTableEntries > 0 )
+ {
+ NoTableEntries--;
+
+ if ((!MemCmp(
+ &ConfigTable[NoTableEntries].VendorGuid,
+ &gEfiAmiTHobListGuid, sizeof(EFI_GUID)
+ )))
+ {
+ HobStart = ConfigTable[NoTableEntries].VendorTable;
+
+ if ( !EFI_ERROR(
+ GetNextGuidHob( &HobStart, HOB_guid, &PtrHob, NULL )
+ ))
+ {
+ return PtrHob;
+ }
+ }
+ }
+ return NULL;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: GetNextGuidHob
+//
+// Description: Find GUID HOB
+//
+// Input: HobStart A pointer to the start hob.
+// Guid A pointer to a guid.
+// Output:
+// Buffer A pointer to the buffer.
+// BufferSize Buffer size.
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS GetNextGuidHob(
+ IN OUT VOID **HobStart,
+ IN EFI_GUID * Guid,
+ OUT VOID **Buffer,
+ OUT UINTN *BufferSize OPTIONAL )
+{
+ EFI_STATUS Status;
+ EFI_PEI_HOB_POINTERS GuidHob;
+
+ if ( Buffer == NULL )
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ for ( Status = EFI_NOT_FOUND; EFI_ERROR( Status );)
+ {
+ GuidHob.Raw = *HobStart;
+
+ if ( END_OF_HOB_LIST( GuidHob ))
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ GuidHob.Raw = GetHob( EFI_HOB_TYPE_GUID_EXTENSION, *HobStart );
+
+ if ( GuidHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION )
+ {
+ if ( CompareGuid( Guid, &GuidHob.Guid->Name ))
+ {
+ Status = EFI_SUCCESS;
+ *Buffer = (VOID*)((UINT8*)(&GuidHob.Guid->Name)
+ + sizeof (EFI_GUID));
+
+ if ( BufferSize != NULL )
+ {
+ *BufferSize = GuidHob.Header->HobLength
+ - sizeof (EFI_HOB_GUID_TYPE);
+ }
+ }
+ }
+
+ *HobStart = GET_NEXT_HOB( GuidHob );
+ }
+
+ return Status;
+}
diff --git a/Core/EM/TCG2/TisLib/TcgCommon.h b/Core/EM/TCG2/TisLib/TcgCommon.h
new file mode 100644
index 0000000..4565f79
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TcgCommon.h
@@ -0,0 +1,305 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TcgCommon.h
+
+ Abstract:
+
+ Header file for TcgCommon.c
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgCommon.h 1 4/21/14 2:14p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:14p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgCommon.h $
+//
+// 1 4/21/14 2:14p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 12:32p Fredericko
+// Sha256 support policy update
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 13 3/19/12 6:14p Fredericko
+//
+// 12 3/29/11 12:24p Fredericko
+//
+// 11 3/28/11 12:18p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 10 5/19/10 5:10p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgCommon.h
+//
+// Description:
+// Header file for TcgCommon.c
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCG_COMMON_H_
+#define _TCG_COMMON_H_
+
+#include <Efi.h>
+#include "TcgPc.h"
+#include "TcgEfiTpm.h"
+#include "Sha.h"
+#include <HOB.h>
+#include "..\Common\Tpm20Includes\Tpm20.h"
+//#include "TcgMisc.h"
+
+#define TcgCommonN2HS( v16 ) TcgCommonH2NS( v16 )
+#define TcgCommonN2HL( v32 ) TcgCommonH2NL( v32 )
+#define EFI_TPL_DRIVER 6
+#define EFI_TPL_APPLICATION 4
+#define EFI_TPL_CALLBACK 8
+#define EFI_TPL_NOTIFY 16
+#define EFI_TPL_HIGH_LEVEL 31
+#define STRING_TOKEN( x ) x
+
+
+#define GET_HOB_TYPE( Hob ) ((Hob).Header->HobType)
+#define GET_HOB_LENGTH( Hob ) ((Hob).Header->HobLength)
+#define GET_NEXT_HOB( Hob ) ((Hob).Raw + GET_HOB_LENGTH( Hob ))
+#define END_OF_HOB_LIST( Hob ) (GET_HOB_TYPE( Hob ) ==\
+ EFI_HOB_TYPE_END_OF_HOB_LIST)
+
+#define TCGPASSTHROUGH( cb, in, out ) \
+ TcgCommonPassThrough( \
+ cb, \
+ sizeof (in) / sizeof (*(in)), \
+ (in), \
+ sizeof (out) / sizeof (*(out)), \
+ (out) \
+ )
+
+
+extern
+UINT16
+__stdcall TcgCommonH2NS (
+ IN UINT16 Val );
+
+extern
+UINT32
+__stdcall TcgCommonH2NL (
+ IN UINT32 Val );
+
+VOID* GetHob (
+ IN UINT16 Type,
+ IN VOID *HobStart );
+
+BOOLEAN CompareGuid (
+ EFI_GUID *G1,
+ EFI_GUID *G2 );
+
+EFI_STATUS GetNextGuidHob (
+ IN OUT VOID **HobStart,
+ IN EFI_GUID * Guid,
+ OUT VOID **Buffer,
+ OUT UINTN*BufferSize OPTIONAL );
+
+extern
+EFI_STATUS
+__stdcall TcgCommonPassThrough (
+ IN VOID *CallbackContext,
+ IN UINT32 NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINT32 NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers );
+
+extern
+VOID
+__stdcall TcgCommonCopyMem (
+ IN VOID *CallbackContext,
+ OUT VOID *Dest,
+ IN VOID *Src,
+ IN UINTN Len );
+
+extern
+EFI_STATUS
+__stdcall TcgCommonLogEvent(
+ IN VOID *CallbackContext,
+ IN TCG_PCR_EVENT *EvtLog,
+ IN OUT UINT32 *TableSize,
+ IN UINT32 MaxSize,
+ IN TCG_PCR_EVENT *NewEntry,
+ IN UINT8 HashAlgorithm );
+
+extern
+EFI_STATUS
+__stdcall TcmCommonLogEvent (
+ IN VOID *CallbackContext,
+ IN TCM_PCR_EVENT *EvtLog,
+ IN OUT UINT32 *TableSize,
+ IN UINT32 MaxSize,
+ IN TCM_PCR_EVENT *NewEntry );
+
+extern
+EFI_STATUS
+__stdcall TcgCommonSha1Start (
+ IN VOID *CallbackContext,
+ IN TCG_ALGORITHM_ID AlgId,
+ OUT UINT32 *MaxBytes );
+
+extern
+EFI_STATUS
+__stdcall TcgCommonSha1Update (
+ IN VOID *CallbackContext,
+ IN VOID *Data,
+ IN UINT32 DataLen,
+ IN UINT32 MaxBytes );
+
+extern
+EFI_STATUS
+__stdcall TcgCommonSha1CompleteExtend (
+ IN VOID *CallbackContext,
+ IN VOID *Data,
+ IN UINT32 DataLen,
+ IN TPM_PCRINDEX PCRIndex,
+ OUT TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue );
+
+
+EFI_STATUS
+__stdcall TcmCommonSha1CompleteExtend(
+ IN VOID *CallbackContext,
+ IN VOID *Data,
+ IN UINT32 DataLen,
+ IN TPM_PCRINDEX PCRIndex,
+ OUT TCM_DIGEST *Digest,
+ OUT TCM_DIGEST *NewPCRValue );
+
+extern
+EFI_STATUS
+__stdcall TcgCommonExtend (
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PCRIndex,
+ IN TCG_DIGEST *Digest,
+ OUT TCG_DIGEST *NewPCRValue );
+
+EFI_STATUS
+__stdcall TcmCommonExtend(
+ IN VOID *CallbackContext,
+ IN TPM_PCRINDEX PCRIndex,
+ IN TCM_DIGEST *Digest,
+ OUT TCM_DIGEST *NewPCRValue );
+
+extern
+EFI_STATUS
+__stdcall SHA1HashAll (
+ IN VOID *CallbackContext,
+ IN VOID *HashData,
+ IN UINTN HashDataLen,
+ OUT TCG_DIGEST *Digest
+ );
+
+EFI_STATUS
+__stdcall SHA2HashAll(
+ IN VOID *CallbackContext,
+ IN VOID *HashData,
+ IN UINTN HashDataLen,
+ OUT TCG_DIGEST *Digest
+ );
+
+EFI_STATUS EfiLibGetSystemConfigurationTable(
+ IN EFI_GUID *TableGuid,
+ IN OUT VOID **Table );
+
+#pragma pack(push,1)
+
+typedef union {
+ UINT8 sha1[SHA1_DIGEST_SIZE];
+ UINT8 sha256[SHA256_DIGEST_SIZE];
+} TPM_COMM_DIGEST_UNION;
+
+typedef struct{
+ UINT16 HashAlgId;
+ TPM_COMM_DIGEST_UNION Digest;
+}TPM_COMM_DIGEST;
+
+#define HASH_ALG_COUNT 2
+
+typedef struct {
+ UINT32 Count;
+ TPM_COMM_DIGEST Digests[HASH_ALG_COUNT];
+}TPM_COMM_DIGEST_LIST;
+
+typedef struct {
+ TPMI_DH_PCR pcrHandle;
+ TPM_COMM_DIGEST_LIST DigestValue;
+} PCR_Extend_In;
+
+typedef struct {
+ TPMI_ST_COMMAND_TAG Tag;
+ UINT32 CommandSize;
+ TPM_CC CommandCode;
+ PCR_Extend_In inputParameters;
+ UINT32 authorizationSize;
+ TPMS_AUTH_SESSION_COMMAND pwapAuth;
+} TPM2_PCRExtend_cmd_t;
+
+typedef struct {
+ TPMI_ST_COMMAND_TAG Tag;
+ UINT32 RespondSize;
+ TPM_RC ResponseCode;
+ UINT32 parameterSize;
+ TPMS_AUTH_SESSION_RESPONSE pwapAuth;
+} TPM2_PCRExtend_res_t;
+
+
+#pragma pack(pop)
+
+extern
+BOOLEAN
+__stdcall AutoSupportType (
+ );
+
+#endif
diff --git a/Core/EM/TCG2/TisLib/TcgEFI12.h b/Core/EM/TCG2/TisLib/TcgEFI12.h
new file mode 100644
index 0000000..9ecfa92
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TcgEFI12.h
@@ -0,0 +1,186 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TpmEfi.h
+
+ Abstract:
+
+ This file contains definitions of structures for TPM and TCG
+ protocols/ppis.
+
+ --*/
+
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgEFI12.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgEFI12.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 2 5/19/10 5:22p Fredericko
+//
+// Included File Header
+// Included File Revision History
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgEFI12.h
+//
+// Description:
+// Contains Industry Standard structures for TCG
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCGEFI_H_
+#define _TCGEFI_H_
+
+#include "TcgTpm12.h"
+#include "TcgPc.h"
+
+#define _TPM_NTH_BIT( x ) (1 << (x))
+#define _TPM_STRUCT_PARTIAL_SIZE( type, field ) \
+ ((UINTN)&(((type*)0)->field))
+
+#pragma pack (push)
+#pragma pack (1)
+
+//
+// TCG_PCClientEventStructure
+//
+#pragma pack (pop)
+
+//
+// Per the EFI Implementation
+//
+typedef TPM_DIGEST TCG_DIGEST;
+
+//
+// TPM_TRANSMIT_BUFFER used by TCG services
+//
+typedef struct _TPM_TRANSMIT_BUFFER
+{
+ VOID *Buffer;
+ UINTN Size;
+} TPM_TRANSMIT_BUFFER;
+
+//
+// Definitons of TPM commands
+//
+
+#pragma pack (push)
+#pragma pack (1)
+
+typedef struct _TPM_1_2_CMD_HEADER
+{
+ TPM_TAG Tag;
+ UINT32 ParamSize;
+ TPM_COMMAND_CODE Ordinal;
+} TPM_1_2_CMD_HEADER;
+
+typedef struct _TPM_1_2_RET_HEADER
+{
+ TPM_TAG Tag;
+ UINT32 ParamSize;
+ TPM_RESULT RetCode;
+} TPM_1_2_RET_HEADER;
+
+//
+// TPM_Startup
+//
+
+typedef struct _TPM_1_2_CMD_STARTUP
+{
+ TPM_1_2_CMD_HEADER Header;
+ TPM_STARTUP_TYPE StartupType;
+} TPM_1_2_CMD_STARTUP;
+
+//
+// TPM_SHA1Start
+//
+
+typedef struct _TPM_1_2_RET_SHA1START
+{
+ TPM_1_2_RET_HEADER Header;
+ UINT32 MaxBytes;
+} TPM_1_2_RET_SHA1START;
+
+//
+// TPM_SHA1Update
+//
+
+typedef struct _TPM_1_2_CMD_SHA1UPDATE
+{
+ TPM_1_2_CMD_HEADER Header;
+ UINT32 NumBytes;
+} TPM_1_2_CMD_SHA1UPDATE;
+
+//
+// TPM_SHA1Complete
+//
+
+typedef TPM_1_2_CMD_SHA1UPDATE TPM_1_2_CMD_SHA1COMPLETE;
+
+typedef struct _TPM_1_2_RET_SHA1COMPLETE
+{
+ TPM_1_2_CMD_HEADER Header;
+ TCG_DIGEST Digest;
+} TPM_1_2_RET_SHA1COMPLETE;
+
+//
+// TPM_SHA1CompleteExtend
+//
+
+typedef struct _TPM_1_2_CMD_SHA1COMPLETEEXTEND
+{
+ TPM_1_2_CMD_HEADER Header;
+ TPM_PCRINDEX PCRIndex;
+ UINT32 NumBytes;
+} TPM_1_2_CMD_SHA1COMPLETEEXTEND;
+
+#pragma pack (pop)
+
+#endif // _TCGEFI_H_
diff --git a/Core/EM/TCG2/TisLib/TcgEfiTpm.h b/Core/EM/TCG2/TisLib/TcgEfiTpm.h
new file mode 100644
index 0000000..3639048
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TcgEfiTpm.h
@@ -0,0 +1,220 @@
+/*++
+
+ Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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.
+
+ Module Name:
+
+ EfiTpm.h
+
+ Abstract:
+
+ EFI definition according to TCG_EFI_Platform_1_20_Final
+
+ See http://trustedcomputinggroup.org for latest specification updates
+
+ --*/
+
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgEfiTpm.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgEfiTpm.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 5 11/17/11 2:28p Fredericko
+// [TAG] EIP75882
+// [Category] New Feature
+// [Description] Measurement of Secureboot variables PK, KEK, DB, DBX
+// and the EFI_Image_Execution_tables
+// [Files] TcgEfiTpm.h
+// AmitcgPlatform.sdl
+// AmiTcgPlatformDxe.c
+// AmiTcgPlatformDxe.h
+//
+// 4 5/19/10 5:24p Fredericko
+// Included File Header
+// Included File Revision History
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgTpm12.h
+//
+// Description:
+// Contains Industry Standard #defines and structures for TCG
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _EFI_TPM_H_
+#define _EFI_TPM_H_
+
+#include <EFI.h>
+
+//
+// The start of TPM return codes
+//
+#define TPM_BASE (EFI_MAX_BIT + (EFI_MAX_BIT >> 1))
+#include "TcgTpm12.h"
+
+//
+// Standard event types
+//
+#define EV_POST_CODE ((TCG_EVENTTYPE) 0x00000001)
+#define EV_SEPARATOR ((TCG_EVENTTYPE) 0x00000004)
+#define EV_S_CRTM_CONTENTS ((TCG_EVENTTYPE) 0x00000007)
+#define EV_S_CRTM_VERSION ((TCG_EVENTTYPE) 0x00000008)
+
+//
+// EFI specific event types
+//
+#define EV_EFI_EVENT_BASE ((TCG_EVENTTYPE) 0x80000000)
+#define EV_EFI_VARIABLE_DRIVER_CONFIG (EV_EFI_EVENT_BASE + 1)
+#define EV_EFI_VARIABLE_BOOT (EV_EFI_EVENT_BASE + 2)
+#define EV_EFI_BOOT_SERVICES_APPLICATION (EV_EFI_EVENT_BASE + 3)
+#define EV_EFI_BOOT_SERVICES_DRIVER (EV_EFI_EVENT_BASE + 4)
+#define EV_EFI_RUNTIME_SERVICES_DRIVER (EV_EFI_EVENT_BASE + 5)
+#define EV_EFI_GPT_EVENT (EV_EFI_EVENT_BASE + 6)
+#define EV_EFI_ACTION (EV_EFI_EVENT_BASE + 7)
+#define EV_EFI_PLATFORM_FIRMWARE_BLOB (EV_EFI_EVENT_BASE + 8)
+#define EV_EFI_HANDOFF_TABLES (EV_EFI_EVENT_BASE + 9)
+#define EV_EFI_SETUP_MODE (EV_EFI_EVENT_BASE + 0x0a)
+#define EV_EFI_PLATFORM_KEY (EV_EFI_EVENT_BASE + 0x0b)
+#define EV_EFI_KEY_EXCHANGE_KEY (EV_EFI_EVENT_BASE + 0x0c)
+#define EV_EFI_AUTHORIZED_DB (EV_EFI_EVENT_BASE + 0x0d)
+#define EV_EFI_FORBIDDEN_DBX (EV_EFI_EVENT_BASE + 0x0e)
+#define EV_EFI_EXECUTION_INFO_TABLE (EV_EFI_EVENT_BASE + 0x0f)
+
+
+//
+// Set structure alignment to 1-byte
+//
+#pragma pack (push, 1)
+
+typedef UINT32 TCG_EVENTTYPE;
+
+#define TCG_DIGEST TPM_DIGEST
+#define TCG_PCRINDEX TPM_PCRINDEX
+
+//
+// TCG_PCR_EVENT
+//
+typedef struct tdTCG_PCR_EVENT
+{
+ TCG_PCRINDEX PCRIndex; // PCRIndex event extended to
+ TCG_EVENTTYPE EventType; // TCG EFI event type
+ TCG_DIGEST Digest; // Value extended into PCRIndex
+ UINT32 EventSize; // Size of the event data
+ UINT8 Event[1]; // The event data
+} TCG_PCR_EVENT;
+
+//
+// TCG_PCR_EVENT_HDR
+//
+typedef struct tdTCG_PCR_EVENT_HDR
+{
+ TCG_PCRINDEX PCRIndex;
+ TCG_EVENTTYPE EventType;
+ TCG_DIGEST Digest;
+ UINT32 EventSize;
+} TCG_PCR_EVENT_HDR;
+
+//
+// EFI_PLATFORM_FIRMWARE_BLOB
+//
+// BlobLength should be of type UINTN but we use UINT64 here
+// because PEI is 32-bit while DXE is 64-bit on x64 platforms
+//
+typedef struct tdEFI_PLATFORM_FIRMWARE_BLOB
+{
+ EFI_PHYSICAL_ADDRESS BlobBase;
+ UINT64 BlobLength;
+} EFI_PLATFORM_FIRMWARE_BLOB;
+
+//
+// EFI_IMAGE_LOAD_EVENT
+//
+// This structure is used in EV_EFI_BOOT_SERVICES_APPLICATION,
+// EV_EFI_BOOT_SERVICES_DRIVER and EV_EFI_RUNTIME_SERVICES_DRIVER
+//
+typedef struct tdEFI_IMAGE_LOAD_EVENT
+{
+ EFI_PHYSICAL_ADDRESS ImageLocationInMemory;
+ UINTN ImageLengthInMemory;
+ UINTN ImageLinkTimeAddress;
+ UINTN LengthOfDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL DevicePath[1];
+} EFI_IMAGE_LOAD_EVENT;
+
+//
+// EFI_HANDOFF_TABLE_POINTERS
+//
+// This structure is used in EV_EFI_HANDOFF_TABLES event to facilitate
+// the measurement of given configuration tables.
+//
+typedef struct tdEFI_HANDOFF_TABLE_POINTERS
+{
+ UINTN NumberOfTables;
+ EFI_CONFIGURATION_TABLE TableEntry[1];
+} EFI_HANDOFF_TABLE_POINTERS;
+
+//
+// EFI_VARIABLE_DATA
+//
+// This structure serves as the header for measuring variables. The name of the
+// variable (in Unicode format) should immediately follow, then the variable
+// data.
+//
+typedef struct tdEFI_VARIABLE_DATA
+{
+ EFI_GUID VariableName;
+ UINTN UnicodeNameLength;
+ UINTN VariableDataLength;
+ CHAR16 UnicodeName[1];
+ INT8 VariableData[1]; // Driver or platform-specific data
+} EFI_VARIABLE_DATA;
+
+//
+// Restore original structure alignment
+//
+#pragma pack (pop)
+
+#endif // _EFI_TPM_H_
diff --git a/Core/EM/TCG2/TisLib/TcgPc.h b/Core/EM/TCG2/TisLib/TcgPc.h
new file mode 100644
index 0000000..18b1a43
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TcgPc.h
@@ -0,0 +1,311 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TpmDev.h
+
+ Abstract:
+
+ Header file for tpm device drivers
+
+ --*/
+
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgPc.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgPc.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 4 3/29/11 12:26p Fredericko
+//
+// 3 3/28/11 12:27p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 2 5/19/10 5:23p Fredericko
+//
+// Included File Header
+// Included File Revision History
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgPc.h
+//
+// Description:
+// Contains Industry Standard #defines and Structures for TCG
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TPMPC_H_
+#define _TPMPC_H_
+
+#include "TcgEfi12.h"
+#include "INTTcgAcpi.h"
+#include "TcmPc.h"
+
+#pragma pack (push)
+#pragma pack (1)
+
+typedef struct _TPM_1_2_REGISTERS
+{
+ UINT8 Access; // 0
+ UINT8 Reserved1[7]; // 1
+ UINT32 IntEnable; // 8
+ UINT8 IntVector; // 0ch
+ UINT8 Reserved2[3]; // 0dh
+ UINT32 IntSts; // 10h
+ UINT32 IntfCapability; // 14h
+ UINT8 Sts; // 18h
+ UINT16 BurstCount; // 19h
+ UINT8 Reserved3[9];
+ UINT32 DataFifo; // 24h
+ UINT8 Reserved4[0xed8]; // 28h
+ UINT16 Vid; // 0f00h
+ UINT16 Did; // 0f02h
+ UINT8 Rid; // 0f04h
+ UINT8 TcgDefined[0x7b]; // 0f05h
+ UINT32 LegacyAddress1; // 0f80h
+ UINT32 LegacyAddress1Ex; // 0f84h
+ UINT32 LegacyAddress2; // 0f88h
+ UINT32 LegacyAddress2Ex; // 0f8ch
+ UINT8 VendorDefined[0x70]; // 0f90h
+} TPM_1_2_REGISTERS;
+
+typedef struct _TCG_ACPI_TABLE
+{
+ EFI_ACPI_DESCRIPTION_HEADER Header;
+ UINT16 Reserved;
+ UINT32 LogMaxLength;
+ EFI_PHYSICAL_ADDRESS LogStart;
+} TCG_ACPI_TABLE;
+
+//
+// Trusted Computing Platform Alliance Capabilities Table (TCPA)
+//
+typedef struct
+{
+ EFI_ACPI_DESCRIPTION_HEADER Header;
+ UINT16 Reserved;
+ UINT32 LogAreaMaxLength;
+ UINT64 LogAreaStartAddress;
+} EFI_ACPI_TCPA_CAPABILITIES_TABLE;
+
+#pragma pack (pop)
+
+typedef volatile TPM_1_2_REGISTERS *TPM_1_2_REGISTERS_PTR;
+
+#define TPM_ACC_VALID _TPM_NTH_BIT( 7 )
+#define TPM_ACC_ACTIVE_LOCALITY _TPM_NTH_BIT( 5 )
+#define TPM_ACC_BEEN_SEIZED _TPM_NTH_BIT( 4 )
+#define TPM_ACC_SEIZE _TPM_NTH_BIT( 3 )
+#define TPM_ACC_PENDING_REQUEST _TPM_NTH_BIT( 2 )
+#define TPM_ACC_REQUEST_USE _TPM_NTH_BIT( 1 )
+#define TPM_ACC_ESTABLISHMENT _TPM_NTH_BIT( 0 )
+
+#define TPM_STS_VALID _TPM_NTH_BIT( 7 )
+#define TPM_STS_READY _TPM_NTH_BIT( 6 )
+#define TPM_STS_GO _TPM_NTH_BIT( 5 )
+#define TPM_STS_DATA_AVAILABLE _TPM_NTH_BIT( 4 )
+#define TPM_STS_EXPECT _TPM_NTH_BIT( 3 )
+#define TPM_STS_RESPONSE_RETRY _TPM_NTH_BIT( 1 )
+
+#define TPM_BASE_ADDRESS 0xFED40000
+
+#define TPM_H2NS( x ) \
+ (((UINT16)(x) << 8) | ((UINT16)(x) >> 8))
+#define TPM_H2NL( x ) \
+ (UINT32)((((UINT32)(x)) >> 24) \
+ | (((x) >> 8) & 0xff00) \
+ | ((x) << 24) \
+ | (((x) & 0xff00) << 8))
+
+#define TPM_N2HS( x ) TPM_H2NS( x )
+#define TPM_N2HL( x ) TPM_H2NL( x )
+
+//
+// PCR Usage
+//
+#define PCRi_CRTM_AND_POST_BIOS 0
+#define PCRi_HOST_PLATFORM_CONFIG 1
+#define PCRi_OPROM_CODE 2
+#define PCRi_OPROM_CONFIG_AND_DATA 3
+#define PCRi_IPL_CODE 4
+#define PCRi_IPL_CONFIG_AND_DATA 5
+#define PCRi_STATE_TRANSITION 6
+#define PCRi_HOST_PLATFORM_MANUFACTURER_CONTROL 7
+
+//
+// TCG Event Logs
+//
+#define TPM_LOG_AREA_MAX_LEN 0x10000
+
+//
+// TCG Event Types
+//
+#define EV_PREBOOT_CERT 0
+#define EV_UNUSED 2
+#define EV_NO_ACTION 3
+#define EV_ACTION 5
+#define EV_EVENT_TAG 6
+#define EV_CPU_MICROCODE 9
+#define EV_PLATFORM_CONFIG_FLAGS 10
+#define EV_TABLE_OF_DEVICES 11
+#define EV_COMPACT_HASH 12
+#define EV_IPL 13
+#define EV_IPL_PARTITION_DATA 14
+#define EV_NONHOST_CODE 15
+#define EV_NONHOST_CONFIG 16
+
+//
+// TCG Event IDs
+//
+#define EV_ID_NULL 0
+#define EV_ID_SMBIOS_RECORD 1
+#define EV_ID_BIS_CERTIFICATE 2
+#define EV_ID_POST_BIOS_STRING 3
+#define EV_ID_ESCD 4
+#define EV_ID_RAW_CMOS 5
+#define EV_ID_RAW_NVRAM 6
+#define EV_ID_OPROM_EXECUTE 7
+#define EV_ID_OPROM_CONFIG 8
+#define EV_ID_OPROM_MICROCODE_UPDATE 9
+
+#pragma pack (push)
+#pragma pack (1)
+
+//
+// _EFI_TCG_EV_S_CRTM_VERSION
+//
+struct _EFI_TCG_EV_S_CRTM_VERSION
+{
+ EFI_GUID VersionGuid;
+};
+
+//
+// _EFI_TCG_EV_POST_CODE
+//
+struct _EFI_TCG_EV_POST_CODE
+{
+ EFI_PHYSICAL_ADDRESS PostCodeAddress;
+ UINT64 PostCodeLength;
+};
+
+//
+// _EFI_TCG_EV_TAG_OPTION_ROM_EXECUTE
+//
+struct _EFI_TCG_EV_TAG_OPTION_ROM_EXECUTE
+{
+ UINT16 Reserved;
+ UINT16 PFA;
+ TCG_DIGEST Hash;
+};
+
+//
+// _EFI_TCG_EV_CPU_MICROCODE
+//
+struct _EFI_TCG_EV_CPU_MICROCODE
+{
+ EFI_PHYSICAL_ADDRESS MicrocodeEntrypoint;
+};
+
+//
+// _EFI_TCG_EV_TAG_EVENT_DATA
+//
+union _EFI_TCG_EV_TAG_EVENT_DATA
+{
+ struct _EFI_TCG_EV_TAG_OPTION_ROM_EXECUTE
+ OptionRomExecute;
+};
+
+//
+// _EFI_TCG_EV_TAG
+//
+struct _EFI_TCG_EV_TAG
+{
+ UINT32 EventID;
+ UINT32 EventSize;
+ union _EFI_TCG_EV_TAG_EVENT_DATA EventData;
+};
+
+//
+// EFI_TCG_PCR_EVENT_HEADER
+//
+typedef struct _EFI_TCG_PCR_EVENT_HEADER
+{
+ TPM_PCRINDEX PCRIndex;
+ UINT32 EventType;
+ TCG_DIGEST Digest;
+ UINT32 EventDataSize;
+} EFI_TCG_PCR_EVENT_HEADER;
+
+//
+// EFI_TCG_PCR_EVENT_DATA
+//
+typedef union _EFI_TCG_PCR_EVENT_DATA
+{
+ struct _EFI_TCG_EV_S_CRTM_VERSION SCrtmVersion;
+ struct _EFI_TCG_EV_POST_CODE PostCode;
+ struct _EFI_TCG_EV_TAG Tagged;
+ struct _EFI_TCG_EV_CPU_MICROCODE Mcu;
+} EFI_TCG_PCR_EVENT_DATA;
+
+//
+// EFI_TCG_PCR_EVENT
+// equivalent to TCG_PCR_EVENT in the TCG PC Client Spec
+//
+typedef struct _EFI_TCG_PCR_EVENT
+{
+ EFI_TCG_PCR_EVENT_HEADER Header;
+ EFI_TCG_PCR_EVENT_DATA Event;
+} EFI_TCG_PCR_EVENT;
+
+#pragma pack (pop)
+
+#endif // _TPMPC_H_
diff --git a/Core/EM/TCG2/TisLib/TcgTpm12.h b/Core/EM/TCG2/TisLib/TcgTpm12.h
new file mode 100644
index 0000000..c20668c
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TcgTpm12.h
@@ -0,0 +1,1973 @@
+/*++
+
+ Copyright (c) 2005 - 2006, Intel Corporation
+ All rights reserved. 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.
+
+ Module Name:
+
+ Tpm12.h
+
+ Abstract:
+
+ TPM Specification data structures (TCG TPM Specification Version 1.2 Revision 94)
+
+ See http://trustedcomputinggroup.org for latest specification updates
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgTpm12.h 1 4/21/14 2:14p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:14p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgTpm12.h $
+//
+// 1 4/21/14 2:14p Fredericko
+//
+// 2 3/17/14 3:03p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 12:32p Fredericko
+// Sha256 support policy update
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 6 3/29/11 12:25p Fredericko
+//
+// 5 3/28/11 12:25p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 4 5/19/10 5:21p Fredericko
+// Included File Header
+// Included File Revision History
+// Code Beautification
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcgTpm12.h
+//
+// Description:
+// Contains Industry Standard #defines for TCG
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TPM12_H_
+#define _TPM12_H_
+
+#include "token.h"
+#include "ZTEICTcmOrdinals.h"
+
+//
+// Structures are all packed on 1-byte alignment
+//
+
+#pragma pack (push)
+#pragma pack (1)
+
+//
+// Part 2, section 2.2: Basic types & Helper redefinitions
+//
+typedef UINT8 TPM_AUTH_DATA_USAGE;
+typedef UINT8 TPM_PAYLOAD_TYPE;
+typedef UINT8 TPM_VERSION_BYTE;
+typedef UINT16 TPM_TAG;
+typedef UINT16 TPM_PROTOCOL_ID;
+typedef UINT16 TPM_STARTUP_TYPE;
+typedef UINT16 TPM_ENC_SCHEME;
+typedef UINT16 TPM_SIG_SCHEME;
+typedef UINT16 TPM_MIGRATE_SCHEME;
+typedef UINT16 TPM_PHYSICAL_PRESENCE;
+typedef UINT16 TPM_ENTITY_TYPE;
+typedef UINT16 TPM_KEY_USAGE;
+typedef UINT16 TPM_EK_TYPE;
+typedef UINT16 TPM_STRUCTURE_TAG;
+typedef UINT16 TPM_PLATFORM_SPECIFIC;
+typedef UINT32 TPM_COMMAND_CODE;
+typedef UINT32 TPM_CAPABILITY_AREA;
+typedef UINT32 TPM_KEY_FLAGS;
+typedef UINT32 TPM_ALGORITHM_ID;
+typedef UINT32 TPM_MODIFIER_INDICATOR;
+typedef UINT32 TPM_ACTUAL_COUNT;
+typedef UINT32 TPM_TRANSPORT_ATTRIBUTES;
+typedef UINT32 TPM_AUTHHANDLE;
+typedef UINT32 TPM_DIRINDEX;
+typedef UINT32 TPM_KEY_HANDLE;
+typedef UINT32 TPM_PCRINDEX;
+typedef UINT32 TPM_RESULT;
+typedef UINT32 TPM_RESOURCE_TYPE;
+typedef UINT32 TPM_KEY_CONTROL;
+typedef UINT32 TPM_NV_INDEX;
+typedef UINT32 TPM_FAMILY_ID;
+typedef UINT32 TPM_FAMILY_VERIFICATION;
+typedef UINT32 TPM_STARTUP_EFFECTS;
+typedef UINT32 TPM_SYM_MODE;
+typedef UINT32 TPM_FAMILY_FLAGS;
+typedef UINT32 TPM_DELEGATE_INDEX;
+typedef UINT32 TPM_CMK_DELEGATE;
+typedef UINT32 TPM_COUNT_ID;
+typedef UINT32 TPM_REDIT_COMMAND;
+typedef UINT32 TPM_TRANSHANDLE;
+typedef UINT32 TPM_HANDLE;
+typedef UINT32 TPM_FAMILY_OPERATION;
+
+//
+// Part 2, section 2.2.4: Vendor specific
+// The following defines allow for the quick specification of a
+// vendor specific item.
+//
+#define TPM_Vendor_Specific32 ((UINT32) 0x00000400)
+#define TPM_Vendor_Specific8 ((UINT8) 0x80)
+
+//
+// Part 2, section 3.1: Structure TAGs
+//
+#define TPM_TAG_CONTEXTBLOB ((TPM_STRUCTURE_TAG) 0x0001)
+#define TPM_TAG_CONTEXT_SENSITIVE ((TPM_STRUCTURE_TAG) 0x0002)
+#define TPM_TAG_CONTEXTPOINTER ((TPM_STRUCTURE_TAG) 0x0003)
+#define TPM_TAG_CONTEXTLIST ((TPM_STRUCTURE_TAG) 0x0004)
+#define TPM_TAG_SIGNINFO ((TPM_STRUCTURE_TAG) 0x0005)
+#define TPM_TAG_PCR_INFO_LONG ((TPM_STRUCTURE_TAG) 0x0006)
+#define TPM_TAG_PERSISTENT_FLAGS ((TPM_STRUCTURE_TAG) 0x0007)
+#define TPM_TAG_VOLATILE_FLAGS ((TPM_STRUCTURE_TAG) 0x0008)
+#define TPM_TAG_PERSISTENT_DATA ((TPM_STRUCTURE_TAG) 0x0009)
+#define TPM_TAG_VOLATILE_DATA ((TPM_STRUCTURE_TAG) 0x000A)
+#define TPM_TAG_SV_DATA ((TPM_STRUCTURE_TAG) 0x000B)
+#define TPM_TAG_EK_BLOB ((TPM_STRUCTURE_TAG) 0x000C)
+#define TPM_TAG_EK_BLOB_AUTH ((TPM_STRUCTURE_TAG) 0x000D)
+#define TPM_TAG_COUNTER_VALUE ((TPM_STRUCTURE_TAG) 0x000E)
+#define TPM_TAG_TRANSPORT_INTERNAL ((TPM_STRUCTURE_TAG) 0x000F)
+#define TPM_TAG_TRANSPORT_LOG_IN ((TPM_STRUCTURE_TAG) 0x0010)
+#define TPM_TAG_TRANSPORT_LOG_OUT ((TPM_STRUCTURE_TAG) 0x0011)
+#define TPM_TAG_AUDIT_EVENT_IN ((TPM_STRUCTURE_TAG) 0x0012)
+#define TPM_TAG_AUDIT_EVENT_OUT ((TPM_STRUCTURE_TAG) 0x0013)
+#define TPM_TAG_CURRENT_TICKS ((TPM_STRUCTURE_TAG) 0x0014)
+#define TPM_TAG_KEY ((TPM_STRUCTURE_TAG) 0x0015)
+#define TPM_TAG_STORED_DATA12 ((TPM_STRUCTURE_TAG) 0x0016)
+#define TPM_TAG_NV_ATTRIBUTES ((TPM_STRUCTURE_TAG) 0x0017)
+#define TPM_TAG_NV_DATA_PUBLIC ((TPM_STRUCTURE_TAG) 0x0018)
+#define TPM_TAG_NV_DATA_SENSITIVE ((TPM_STRUCTURE_TAG) 0x0019)
+#define TPM_TAG_DELEGATIONS ((TPM_STRUCTURE_TAG) 0x001A)
+#define TPM_TAG_DELEGATE_PUBLIC ((TPM_STRUCTURE_TAG) 0x001B)
+#define TPM_TAG_DELEGATE_TABLE_ROW ((TPM_STRUCTURE_TAG) 0x001C)
+#define TPM_TAG_TRANSPORT_AUTH ((TPM_STRUCTURE_TAG) 0x001D)
+#define TPM_TAG_TRANSPORT_PUBLIC ((TPM_STRUCTURE_TAG) 0x001E)
+#define TPM_TAG_PERMANENT_FLAGS ((TPM_STRUCTURE_TAG) 0x001F)
+#define TPM_TAG_STCLEAR_FLAGS ((TPM_STRUCTURE_TAG) 0x0020)
+#define TPM_TAG_STANY_FLAGS ((TPM_STRUCTURE_TAG) 0x0021)
+#define TPM_TAG_PERMANENT_DATA ((TPM_STRUCTURE_TAG) 0x0022)
+#define TPM_TAG_STCLEAR_DATA ((TPM_STRUCTURE_TAG) 0x0023)
+#define TPM_TAG_STANY_DATA ((TPM_STRUCTURE_TAG) 0x0024)
+#define TPM_TAG_FAMILY_TABLE_ENTRY ((TPM_STRUCTURE_TAG) 0x0025)
+#define TPM_TAG_DELEGATE_SENSITIVE ((TPM_STRUCTURE_TAG) 0x0026)
+#define TPM_TAG_DELG_KEY_BLOB ((TPM_STRUCTURE_TAG) 0x0027)
+#define TPM_TAG_KEY12 ((TPM_STRUCTURE_TAG) 0x0028)
+#define TPM_TAG_CERTIFY_INFO2 ((TPM_STRUCTURE_TAG) 0x0029)
+#define TPM_TAG_DELEGATE_OWNER_BLOB ((TPM_STRUCTURE_TAG) 0x002A)
+#define TPM_TAG_EK_BLOB_ACTIVATE ((TPM_STRUCTURE_TAG) 0x002B)
+#define TPM_TAG_DAA_BLOB ((TPM_STRUCTURE_TAG) 0x002C)
+#define TPM_TAG_DAA_CONTEXT ((TPM_STRUCTURE_TAG) 0x002D)
+#define TPM_TAG_DAA_ENFORCE ((TPM_STRUCTURE_TAG) 0x002E)
+#define TPM_TAG_DAA_ISSUER ((TPM_STRUCTURE_TAG) 0x002F)
+#define TPM_TAG_CAP_VERSION_INFO ((TPM_STRUCTURE_TAG) 0x0030)
+#define TPM_TAG_DAA_SENSITIVE ((TPM_STRUCTURE_TAG) 0x0031)
+#define TPM_TAG_DAA_TPM ((TPM_STRUCTURE_TAG) 0x0032)
+#define TPM_TAG_CMK_MIGAUTH ((TPM_STRUCTURE_TAG) 0x0033)
+#define TPM_TAG_CMK_SIGTICKET ((TPM_STRUCTURE_TAG) 0x0034)
+#define TPM_TAG_CMK_MA_APPROVAL ((TPM_STRUCTURE_TAG) 0x0035)
+#define TPM_TAG_QUOTE_INFO2 ((TPM_STRUCTURE_TAG) 0x0036)
+
+//
+// Part 2, section 4: TPM Types
+//
+
+//
+// Part 2, section 4.1: TPM_RESOURCE_TYPE
+//
+#define TPM_RT_KEY ((TPM_RESOURCE_TYPE) 0x00000001) // The handle is a key handle and is the result of a LoadKey type operation
+#define TPM_RT_AUTH ((TPM_RESOURCE_TYPE) 0x00000002) // The handle is an authorization handle. Auth handles come from TPM_OIAP, TPM_OSAP and TPM_DSAP
+#define TPM_RT_HASH ((TPM_RESOURCE_TYPE) 0x00000003) // Reserved for hashes
+#define TPM_RT_TRANS ((TPM_RESOURCE_TYPE) 0x00000004) // The handle is for a transport session. Transport handles come from TPM_EstablishTransport
+#define TPM_RT_CONTEXT ((TPM_RESOURCE_TYPE) 0x00000005) // Resource wrapped and held outside the TPM using the context save/restore commands
+#define TPM_RT_COUNTER ((TPM_RESOURCE_TYPE) 0x00000006) // Reserved for counters
+#define TPM_RT_DELEGATE ((TPM_RESOURCE_TYPE) 0x00000007) // The handle is for a delegate row. These are the internal rows held in NV storage by the TPM
+#define TPM_RT_DAA_TPM ((TPM_RESOURCE_TYPE) 0x00000008) // The value is a DAA TPM specific blob
+#define TPM_RT_DAA_V0 ((TPM_RESOURCE_TYPE) 0x00000009) // The value is a DAA V0 parameter
+#define TPM_RT_DAA_V1 ((TPM_RESOURCE_TYPE) 0x0000000A) // The value is a DAA V1 parameter
+
+//
+// Part 2, section 4.2: TPM_PAYLOAD_TYPE
+//
+#define TPM_PT_ASYM ((TPM_PAYLOAD_TYPE) 0x01) // The entity is an asymmetric key
+#define TPM_PT_BIND ((TPM_PAYLOAD_TYPE) 0x02) // The entity is bound data
+#define TPM_PT_MIGRATE ((TPM_PAYLOAD_TYPE) 0x03) // The entity is a migration blob
+#define TPM_PT_MAINT ((TPM_PAYLOAD_TYPE) 0x04) // The entity is a maintenance blob
+#define TPM_PT_SEAL ((TPM_PAYLOAD_TYPE) 0x05) // The entity is sealed data
+#define TPM_PT_MIGRATE_RESTRICTED ((TPM_PAYLOAD_TYPE) 0x06) // The entity is a restricted-migration asymmetric key
+#define TPM_PT_MIGRATE_EXTERNAL ((TPM_PAYLOAD_TYPE) 0x07) // The entity is a external migratable key
+#define TPM_PT_CMK_MIGRATE ((TPM_PAYLOAD_TYPE) 0x08) // The entity is a CMK migratable blob
+#define TPM_PT_VENDOR_SPECIFIC ((TPM_PAYLOAD_TYPE) 0x80) // 0x80 - 0xFF Vendor specific payloads
+
+//
+// Part 2, section 4.3: TPM_ENTIRY_TYPE
+//
+#define TPM_ET_KEYHANDLE ((UINT16) 0x0001) // The entity is a keyHandle or key
+#define TPM_ET_OWNER ((UINT16) 0x0002) // The entity is the TPM Owner
+#define TPM_ET_DATA ((UINT16) 0x0003) // The entity is some data
+#define TPM_ET_SRK ((UINT16) 0x0004) // The entity is the SRK
+#define TPM_ET_KEY ((UINT16) 0x0005) // The entity is a key or keyHandle
+#define TPM_ET_REVOKE ((UINT16) 0x0006) // The entity is the RevokeTrust value
+#define TPM_ET_DEL_OWNER_BLOB ((UINT16) 0x0007) // The entity is a delegate owner blob
+#define TPM_ET_DEL_ROW ((UINT16) 0x0008) // The entity is a delegate row
+#define TPM_ET_DEL_KEY_BLOB ((UINT16) 0x0009) // The entity is a delegate key blob
+#define TPM_ET_COUNTER ((UINT16) 0x000A) // The entity is a counter
+#define TPM_ET_NV ((UINT16) 0x000B) // The entity is a NV index
+#define TPM_ET_RESERVED_HANDLE ((UINT16) 0x0040) // Reserved. This value avoids collisions with the handle MSB setting.
+//
+// TPM_ENTITY_TYPE MSB Values: The MSB is used to indicate the ADIP encryption sheme when applicable
+//
+#define TPM_ET_XOR ((UINT16) 0x0000) // ADIP encryption scheme: XOR
+#define TPM_ET_AES128 ((UINT16) 0x0006) // ADIP encryption scheme: AES 128 bits
+
+//
+// Part 2, section 4.4.1: Reserved Key Handles
+//
+#define TPM_KH_SRK ((TPM_KEY_HANDLE) 0x40000000) // The handle points to the SRK
+#define TPM_KH_OWNER ((TPM_KEY_HANDLE) 0x40000001) // The handle points to the TPM Owner
+#define TPM_KH_REVOKE ((TPM_KEY_HANDLE) 0x40000002) // The handle points to the RevokeTrust value
+#define TPM_KH_TRANSPORT ((TPM_KEY_HANDLE) 0x40000003) // The handle points to the EstablishTransport static authorization
+#define TPM_KH_OPERATOR ((TPM_KEY_HANDLE) 0x40000004) // The handle points to the Operator auth
+#define TPM_KH_ADMIN ((TPM_KEY_HANDLE) 0x40000005) // The handle points to the delegation administration auth
+#define TPM_KH_EK ((TPM_KEY_HANDLE) 0x40000006) // The handle points to the PUBEK, only usable with TPM_OwnerReadInternalPub
+
+//
+// Part 2, section 4.5: TPM_STARTUP_TYPE
+//
+#define TPM_ST_CLEAR ((TPM_STARTUP_TYPE) 0x0001) // The TPM is starting up from a clean state
+#define TPM_ST_STATE ((TPM_STARTUP_TYPE) 0x0002) // The TPM is starting up from a saved state
+#define TPM_ST_DEACTIVATED ((TPM_STARTUP_TYPE) 0x0003) // The TPM is to startup and set the deactivated flag to TRUE
+
+//
+// Part 2, section 4.6: TPM_STATUP_EFFECTS
+// The table makeup is still an open issue.
+//
+
+//
+// Part 2, section 4.7: TPM_PROTOCOL_ID
+//
+#define TPM_PID_OIAP ((TPM_PROTOCOL_ID) 0x0001) // The OIAP protocol.
+#define TPM_PID_OSAP ((TPM_PROTOCOL_ID) 0x0002) // The OSAP protocol.
+#define TPM_PID_ADIP ((TPM_PROTOCOL_ID) 0x0003) // The ADIP protocol.
+#define TPM_PID_ADCP ((TPM_PROTOCOL_ID) 0x0004) // The ADCP protocol.
+#define TPM_PID_OWNER ((TPM_PROTOCOL_ID) 0x0005) // The protocol for taking ownership of a TPM.
+#define TPM_PID_DSAP ((TPM_PROTOCOL_ID) 0x0006) // The DSAP protocol
+#define TPM_PID_TRANSPORT ((TPM_PROTOCOL_ID) 0x0007) // The transport protocol
+
+//
+// Part 2, section 4.8: TPM_ALGORITHM_ID
+// The TPM MUST support the algorithms TPM_ALG_RSA, TPM_ALG_SHA, TPM_ALG_HMAC,
+// TPM_ALG_MGF1
+//
+#define TPM_ALG_RSA ((TPM_ALGORITHM_ID) 0x00000001) // The RSA algorithm.
+#define TPM_ALG_DES ((TPM_ALGORITHM_ID) 0x00000002) // The DES algorithm
+#define TPM_ALG_3DES ((TPM_ALGORITHM_ID) 0x00000003) // The 3DES algorithm in EDE mode
+#define TPM_ALG_SHA ((TPM_ALGORITHM_ID) 0x00000004) // The SHA1 algorithm
+#define TPM_ALG_HMAC ((TPM_ALGORITHM_ID) 0x00000005) // The RFC 2104 HMAC algorithm
+#define TPM_ALG_AES128 ((TPM_ALGORITHM_ID) 0x00000006) // The AES algorithm, key size 128
+#define TPM_ALG_MGF1 ((TPM_ALGORITHM_ID) 0x00000007) // The XOR algorithm using MGF1 to create a string the size of the encrypted block
+#define TPM_ALG_AES192 ((TPM_ALGORITHM_ID) 0x00000008) // AES, key size 192
+#define TPM_ALG_AES256 ((TPM_ALGORITHM_ID) 0x00000009) // AES, key size 256
+#define TPM_ALG_XOR ((TPM_ALGORITHM_ID) 0x0000000A) // XOR using the rolling nonces
+
+//
+// Part 2, section 4.9: TPM_PHYSICAL_PRESENCE
+//
+#define TPM_PHYSICAL_PRESENCE_HW_DISABLE ((TPM_PHYSICAL_PRESENCE) 0x0200) // Sets the physicalPresenceHWEnable to FALSE
+#define TPM_PHYSICAL_PRESENCE_CMD_DISABLE ((TPM_PHYSICAL_PRESENCE) 0x0100) // Sets the physicalPresenceCMDEnable to FALSE
+#define TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK ((TPM_PHYSICAL_PRESENCE) 0x0080) // Sets the physicalPresenceLifetimeLock to TRUE
+#define TPM_PHYSICAL_PRESENCE_HW_ENABLE ((TPM_PHYSICAL_PRESENCE) 0x0040) // Sets the physicalPresenceHWEnable to TRUE
+#define TPM_PHYSICAL_PRESENCE_CMD_ENABLE ((TPM_PHYSICAL_PRESENCE) 0x0020) // Sets the physicalPresenceCMDEnable to TRUE
+#define TPM_PHYSICAL_PRESENCE_NOTPRESENT ((TPM_PHYSICAL_PRESENCE) 0x0010) // Sets PhysicalPresence = FALSE
+#define TPM_PHYSICAL_PRESENCE_PRESENT ((TPM_PHYSICAL_PRESENCE) 0x0008) // Sets PhysicalPresence = TRUE
+#define TPM_PHYSICAL_PRESENCE_LOCK ((TPM_PHYSICAL_PRESENCE) 0x0004) // Sets PhysicalPresenceLock = TRUE
+
+//
+// Part 2, section 4.10: TPM_MIGRATE_SCHEME
+//
+#define TPM_MS_MIGRATE ((TPM_MIGRATE_SCHEME) 0x0001) // A public key that can be used with all TPM migration commands other than 'ReWrap' mode.
+#define TPM_MS_REWRAP ((TPM_MIGRATE_SCHEME) 0x0002) // A public key that can be used for the ReWrap mode of TPM_CreateMigrationBlob.
+#define TPM_MS_MAINT ((TPM_MIGRATE_SCHEME) 0x0003) // A public key that can be used for the Maintenance commands
+#define TPM_MS_RESTRICT_MIGRATE ((TPM_MIGRATE_SCHEME) 0x0004) // The key is to be migrated to a Migration Authority.
+#define TPM_MS_RESTRICT_APPROVE_DOUBLE ((TPM_MIGRATE_SCHEME) 0x0005) // The key is to be migrated to an entity approved by a Migration Authority using double wrapping
+
+//
+// Part 2, section 4.11: TPM_EK_TYPE
+//
+#define TPM_EK_TYPE_ACTIVATE ((TPM_EK_TYPE) 0x0001) // The blob MUST be TPM_EK_BLOB_ACTIVATE
+#define TPM_EK_TYPE_AUTH ((TPM_EK_TYPE) 0x0002) // The blob MUST be TPM_EK_BLOB_AUTH
+
+//
+// Part 2, section 4.12: TPM_PLATFORM_SPECIFIC
+//
+#define TPM_PS_PC_11 ((TPM_PLATFORM_SPECIFIC) 0x0001) // PC Specific version 1.1
+#define TPM_PS_PC_12 ((TPM_PLATFORM_SPECIFIC) 0x0002) // PC Specific version 1.2
+#define TPM_PS_PDA_12 ((TPM_PLATFORM_SPECIFIC) 0x0003) // PDA Specific version 1.2
+#define TPM_PS_Server_12 ((TPM_PLATFORM_SPECIFIC) 0x0004) // Server Specific version 1.2
+#define TPM_PS_Mobile_12 ((TPM_PLATFORM_SPECIFIC) 0x0005) // Mobil Specific version 1.2
+
+//
+// Part 2, section 5: Basic Structures
+//
+
+//
+// Part 2, section 5.1: TPM_STRUCT_VER
+//
+typedef struct tdTPM_STRUCT_VER
+{
+ UINT8 major;
+ UINT8 minor;
+ UINT8 revMajor;
+ UINT8 revMinor;
+} TPM_STRUCT_VER;
+
+//
+// Part 2, section 5.3: TPM_VERSION
+//
+typedef struct tdTPM_VERSION
+{
+ TPM_VERSION_BYTE major;
+ TPM_VERSION_BYTE minor;
+ UINT8 revMajor;
+ UINT8 revMinor;
+} TPM_VERSION;
+
+
+//
+// Part 2, section 5.4: TPM_DIGEST
+//
+#define TPM_SHA1_160_HASH_LEN 0x14
+#define TPM_SHA1BASED_NONCE_LEN TPM_SHA1_160_HASH_LEN
+
+#define TPM_SHA2_256_HASH_LEN 0x20
+#define TPM_SHA2BASED_NONCE_LEN TPM_SHA2_256_HASH_LEN
+
+
+//redefine TPM digest into a UNION so that we can support
+//sha1 and sha2 and other has functions at the same time
+typedef struct tdTPM_DIGEST
+{
+ UINT8 digest[TPM_SHA1_160_HASH_LEN];
+} TPM_DIGEST;
+
+typedef struct tdTCM_DIGEST
+{
+ UINT8 digest[TPM_SHA2BASED_NONCE_LEN];
+} TCM_DIGEST;
+
+
+typedef TPM_DIGEST TPM_CHOSENID_HASH; // This SHALL be the digest of the chosen identityLabel and privacyCA for a new TPM identity.
+typedef TPM_DIGEST TPM_COMPOSITE_HASH; // This SHALL be the hash of a list of PCR indexes and PCR values that a key or data is bound to.
+typedef TPM_DIGEST TPM_DIRVALUE; // This SHALL be the value of a DIR register
+typedef TPM_DIGEST TPM_HMAC;
+typedef TPM_DIGEST TPM_PCRVALUE; // The value inside of the PCR
+typedef TPM_DIGEST TPM_AUDITDIGEST; // This SHALL be the value of the current internal audit state
+typedef TPM_DIGEST TPM_DAA_TPM_SEED; // This SHALL be a random value generated by a TPM immediately after the EK is installed in that TPM, whenever an EK is installed in that TPM
+typedef TPM_DIGEST TPM_DAA_CONTEXT_SEED; // This SHALL be a random value
+
+//
+// Part 2, section 5.5: TPM_NONCE
+//
+typedef struct tdTPM_NONCE
+{
+ UINT8 nonce[20];
+} TPM_NONCE;
+
+//
+// Part 2, section 5.6: TPM_AUTHDATA
+//
+typedef UINT8 tdTPM_AUTHDATA[20];
+typedef tdTPM_AUTHDATA TPM_AUTHDATA;
+typedef TPM_AUTHDATA TPM_SECRET;
+typedef TPM_AUTHDATA TPM_ENCAUTH;
+
+//
+// Part 2, section 5.7: TPM_KEY_HANDLE_LIST
+// Size of handle is loaded * sizeof(TPM_KEY_HANDLE)
+//
+typedef struct tdTPM_KEY_HANDLE_LIST
+{
+ UINT16 loaded;
+ TPM_KEY_HANDLE handle[1];
+} TPM_KEY_HANDLE_LIST;
+
+//
+// Part 2, section 5.8: TPM_KEY_USAGE values
+//
+
+#define TPM_KEY_SIGNING ((UINT16) 0x0010)
+// TPM_KEY_SIGNING SHALL indicate a signing key. The [private] key SHALL be
+// used for signing operations, only. This means that it MUST be a leaf of the
+// Protected Storage key hierarchy.
+
+#define TPM_KEY_STORAGE ((UINT16) 0x0011)
+// TPM_KEY_STORAGE SHALL indicate a storage key. The key SHALL be used to wrap
+// and unwrap other keys in the Protected Storage hierarchy
+
+#define TPM_KEY_IDENTITY ((UINT16) 0x0012)
+// TPM_KEY_IDENTITY SHALL indicate an identity key. The key SHALL be used for
+// operations that require a TPM identity, only.
+
+#define TPM_KEY_AUTHCHANGE ((UINT16) 0x0013)
+// TPM_KEY_AUTHCHANGE SHALL indicate an ephemeral key that is in use during
+// the ChangeAuthAsym process, only.
+
+#define TPM_KEY_BIND ((UINT16) 0x0014)
+// TPM_KEY_BIND SHALL indicate a key that can be used for TPM_Bind and
+// TPM_Unbind operations only.
+
+#define TPM_KEY_LEGACY ((UINT16) 0x0015)
+// TPM_KEY_LEGACY SHALL indicate a key that can perform signing and binding
+// operations. The key MAY be used for both signing and binding operations.
+// The TPM_KEY_LEGACY key type is to allow for use by applications where both
+// signing and encryption operations occur with the same key. The use of this
+// key type is not recommended TPM_KEY_MIGRATE 0x0016 This SHALL indicate a
+// key in use for TPM_MigrateKey
+
+#define TPM_KEY_MIGRATE ((UINT16) 0x0016)
+// TPM_KEY_MIGRAGE SHALL indicate a key in use for TPM_MigrateKey
+
+//
+// Part 2, section 5.8.1: Encryption/Signature schemes
+//
+
+#define TPM_ES_NONE ((TPM_ENC_SCHEME) 0x0001)
+#define TPM_ES_RSAESPKCSv15 ((TPM_ENC_SCHEME) 0x0002)
+#define TPM_ES_RSAESOAEP_SHA1_MGF1 ((TPM_ENC_SCHEME) 0x0003)
+#define TPM_ES_SYM_CNT ((TPM_ENC_SCHEME) 0x0004)
+#define TPM_ES_SYM_OFB ((TPM_ENC_SCHEME) 0x0005)
+
+#define TPM_SS_NONE ((TPM_SIG_SCHEME) 0x0001)
+#define TPM_SS_RSASSAPKCS1v15_SHA1 ((TPM_SIG_SCHEME) 0x0002)
+#define TPM_SS_RSASSAPKCS1v15_DER ((TPM_SIG_SCHEME) 0x0003)
+#define TPM_SS_RSASSAPKCS1v15_INFO ((TPM_SIG_SCHEME) 0x0004)
+
+//
+// Part 2, section 5.9: TPM_AUTH_DATA_USAGE values
+//
+#define TPM_AUTH_NEVER ((TPM_AUTH_DATA_USAGE) 0x00)
+#define TPM_AUTH_ALWAYS ((TPM_AUTH_DATA_USAGE) 0x01)
+#define TPM_AUTH_PRIV_USE_ONLY ((TPM_AUTH_DATA_USAGE) 0x03)
+
+//
+// Part 2, section 5.10: TPM_KEY_FLAGS
+//
+enum tdTPM_KEY_FLAGS
+{
+ redirection = 0x00000001,
+ migratable = 0x00000002,
+ isVolatile = 0x00000004,
+ pcrIgnoredOnRead = 0x00000008,
+ migrateAuthority = 0x00000010
+};
+
+//
+// Part 2, section 5.11: TPM_CHANGEAUTH_VALIDATE
+//
+typedef struct tdTPM_CHANGEAUTH_VALIDATE
+{
+ TPM_SECRET newAuthSecret;
+ TPM_NONCE n1;
+} TPM_CHANGEAUTH_VALIDATE;
+
+//
+// Part 2, section 5.12: TPM_MIGRATIONKEYAUTH
+// decalared after section 10 to catch declaration of TPM_PUBKEY
+//
+// Part 2 section 10.1: TPM_KEY_PARMS
+// [size_is(parmSize)] BYTE* parms;
+//
+typedef struct tdTPM_KEY_PARMS
+{
+ TPM_ALGORITHM_ID algorithmID;
+ TPM_ENC_SCHEME encScheme;
+ TPM_SIG_SCHEME sigScheme;
+ UINT32 parmSize;
+ UINT8 *parms;
+} TPM_KEY_PARMS;
+
+//
+// Part 2, section 10.4: TPM_STORE_PUBKEY
+//
+typedef struct tdTPM_STORE_PUBKEY
+{
+ UINT32 keyLength;
+ UINT8 key[1];
+} TPM_STORE_PUBKEY;
+
+//
+// Part 2, section 10.5: TPM_PUBKEY
+//
+typedef struct tdTPM_PUBKEY
+{
+ TPM_KEY_PARMS algorithmParms;
+ TPM_STORE_PUBKEY pubKey;
+} TPM_PUBKEY;
+
+//
+// Part 2, section 5.12: TPM_MIGRATIONKEYAUTH
+//
+typedef struct tdTPM_MIGRATIONKEYAUTH
+{
+ TPM_PUBKEY migrationKey;
+ TPM_MIGRATE_SCHEME migrationScheme;
+ TPM_DIGEST digest;
+} TPM_MIGRATIONKEYAUTH;
+
+//
+// Part 2, section 5.13: TPM_COUNTER_VALUE
+//
+typedef struct tdTPM_COUNTER_VALUE
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT8 label[4];
+ TPM_ACTUAL_COUNT counter;
+} TPM_COUNTER_VALUE;
+
+//
+// Part 2, section 5.14: TPM_SIGN_INFO
+// Size of data indicated by dataLen
+//
+typedef struct tdTPM_SIGN_INFO
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT8 fixed[4];
+ TPM_NONCE replay;
+ UINT32 dataLen;
+ UINT8 *data;
+} TPM_SIGN_INFO;
+
+//
+// Part 2, section 5.15: TPM_MSA_COMPOSITE
+// Number of migAuthDigest indicated by MSAlist
+//
+typedef struct tdTPM_MSA_COMPOSITE
+{
+ UINT32 MSAlist;
+ TPM_DIGEST migAuthDigest[1];
+} TPM_MSA_COMPOSITE;
+
+//
+// Part 2, section 5.16: TPM_CMK_AUTH
+//
+typedef struct tdTPM_CMK_AUTH
+{
+ TPM_DIGEST migrationAuthorityDigest;
+ TPM_DIGEST destinationKeyDigest;
+ TPM_DIGEST sourceKeyDigest;
+} TPM_CMK_AUTH;
+
+//
+// Part 2, section 5.17: TPM_CMK_DELEGATE
+//
+#define TPM_CMK_DELEGATE_SIGNING (((TPM_CMK_DELEGATE)1) << 31)
+#define TPM_CMK_DELEGATE_STORAGE (((TPM_CMK_DELEGATE)1) << 30)
+#define TPM_CMK_DELEGATE_BIND (((TPM_CMK_DELEGATE)1) << 29)
+#define TPM_CMK_DELEGATE_LEGACY (((TPM_CMK_DELEGATE)1) << 28)
+#define TPM_CMK_DELEGATE_MIGRATE (((TPM_CMK_DELEGATE)1) << 27)
+
+//
+// Part 2, section 5.18: TPM_SELECT_SIZE
+//
+typedef struct tdTPM_SELECT_SIZE
+{
+ UINT8 major;
+ UINT8 minor;
+ UINT16 reqSize;
+} TPM_SELECT_SIZE;
+
+//
+// Part 2, section 5,19: TPM_CMK_MIGAUTH
+//
+typedef struct tdTPM_CMK_MIGAUTH
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DIGEST msaDigest;
+ TPM_DIGEST pubKeyDigest;
+} TPM_CMK_MIGAUTH;
+
+//
+// Part 2, section 5.20: TPM_CMK_SIGTICKET
+//
+typedef struct tdTPM_CMK_SIGTICKET
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DIGEST verKeyDigest;
+ TPM_DIGEST signedData;
+} TPM_CMK_SIGTICKET;
+
+//
+// Part 2, section 5.21: TPM_CMK_MA_APPROVAL
+//
+typedef struct tdTPM_CMK_MA_APPROVAL
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DIGEST migrationAuthorityDigest;
+} TPM_CMK_MA_APPROVAL;
+
+//
+// Part 2, section 6: Command Tags
+//
+#define TPM_TAG_RQU_COMMAND ((TPM_STRUCTURE_TAG) 0x00C1)
+#define TPM_TAG_RQU_AUTH1_COMMAND ((TPM_STRUCTURE_TAG) 0x00C2)
+#define TPM_TAG_RQU_AUTH2_COMMAND ((TPM_STRUCTURE_TAG) 0x00C3)
+#define TPM_TAG_RSP_COMMAND ((TPM_STRUCTURE_TAG) 0x00C4)
+#define TPM_TAG_RSP_AUTH1_COMMAND ((TPM_STRUCTURE_TAG) 0x00C5)
+#define TPM_TAG_RSP_AUTH2_COMMAND ((TPM_STRUCTURE_TAG) 0x00C6)
+
+//
+// Part 2, section 7.1: TPM_PERMANENT_FLAGS
+//
+typedef struct tdTPM_PERMANENT_FLAGS
+{
+ TPM_STRUCTURE_TAG tag;
+ BOOLEAN disable;
+ BOOLEAN ownership;
+ BOOLEAN deactivated;
+ BOOLEAN readPubek;
+ BOOLEAN disableOwnerClear;
+ BOOLEAN allowMaintenance;
+ BOOLEAN physicalPresenceLifetimeLock;
+ BOOLEAN physicalPresenceHWEnable;
+ BOOLEAN physicalPresenceCMDEnable;
+ BOOLEAN CEKPUsed;
+ BOOLEAN TPMpost;
+ BOOLEAN TPMpostLock;
+ BOOLEAN FIPS;
+ BOOLEAN operator;
+ BOOLEAN enableRevokeEK;
+ BOOLEAN nvLocked;
+ BOOLEAN readSRKPub;
+ BOOLEAN tpmEstablished;
+ BOOLEAN maintenanceDone;
+} TPM_PERMANENT_FLAGS;
+
+//
+// Part 2, section 7.1.1: PERMANENT_FLAGS Subcap for SetCapability
+//
+#define TPM_PF_DISABLE ((TPM_CAPABILITY_AREA) 1)
+#define TPM_PF_OWNERSHIP ((TPM_CAPABILITY_AREA) 2)
+#define TPM_PF_DEACTIVATED ((TPM_CAPABILITY_AREA) 3)
+#define TPM_PF_READPUBEK ((TPM_CAPABILITY_AREA) 4)
+#define TPM_PF_DISABLEOWNERCLEAR ((TPM_CAPABILITY_AREA) 5)
+#define TPM_PF_ALLOWMAINTENANCE ((TPM_CAPABILITY_AREA) 6)
+#define TPM_PF_PHYSICALPRESENCELIFETIMELOCK ((TPM_CAPABILITY_AREA) 7)
+#define TPM_PF_PHYSICALPRESENCEHWENABLE ((TPM_CAPABILITY_AREA) 8)
+#define TPM_PF_PHYSICALPRESENCECMDENABLE ((TPM_CAPABILITY_AREA) 9)
+#define TPM_PF_CEKPUSED ((TPM_CAPABILITY_AREA) 10)
+#define TPM_PF_TPMPOST ((TPM_CAPABILITY_AREA) 11)
+#define TPM_PF_TPMPOSTLOCK ((TPM_CAPABILITY_AREA) 12)
+#define TPM_PF_FIPS ((TPM_CAPABILITY_AREA) 13)
+#define TPM_PF_OPERATOR ((TPM_CAPABILITY_AREA) 14)
+#define TPM_PF_ENABLEREVOKEEK ((TPM_CAPABILITY_AREA) 15)
+#define TPM_PF_NV_LOCKED ((TPM_CAPABILITY_AREA) 16)
+#define TPM_PF_READSRKPUB ((TPM_CAPABILITY_AREA) 17)
+#define TPM_PF_TPMESTABLISHED ((TPM_CAPABILITY_AREA) 18)
+#define TPM_PF_MAINTENANCEDONE ((TPM_CAPABILITY_AREA) 19)
+
+//
+// Part 2, section 7.2: TPM_STCLEAR_FLAGS
+//
+typedef struct tdTPM_STCLEAR_FLAGS
+{
+ TPM_STRUCTURE_TAG tag;
+ BOOLEAN deactivated;
+ BOOLEAN disableForceClear;
+ BOOLEAN physicalPresence;
+ BOOLEAN physicalPresenceLock;
+ BOOLEAN bGlobalLock;
+} TPM_STCLEAR_FLAGS;
+
+//
+// Part 2, section 7.2.1: STCLEAR_FLAGS Subcap for SetCapability
+//
+#define TPM_SF_DEACTIVATED ((TPM_CAPABILITY_AREA) 1)
+#define TPM_SF_DISABLEFORCECLEAR ((TPM_CAPABILITY_AREA) 2)
+#define TPM_SF_PHYSICALPRESENCE ((TPM_CAPABILITY_AREA) 3)
+#define TPM_SF_PHYSICALPRESENCELOCK ((TPM_CAPABILITY_AREA) 4)
+#define TPM_SF_BGLOBALLOCK ((TPM_CAPABILITY_AREA) 5)
+
+//
+// Part 2, section 7.3: TPM_STANY_FLAGS
+//
+typedef struct tdTPM_STANY_FLAGS
+{
+ TPM_STRUCTURE_TAG tag;
+ BOOLEAN postInitialise;
+ TPM_MODIFIER_INDICATOR localityModifier;
+ BOOLEAN transportExclusive;
+ BOOLEAN TOSPresent;
+} TPM_STANY_FLAGS;
+
+//
+// Part 2, section 7.3.1: STANY_FLAGS Subcap for SetCapability
+//
+#define TPM_AF_POSTINITIALISE ((TPM_CAPABILITY_AREA) 1)
+#define TPM_AF_LOCALITYMODIFIER ((TPM_CAPABILITY_AREA) 2)
+#define TPM_AF_TRANSPORTEXCLUSIVE ((TPM_CAPABILITY_AREA) 3)
+#define TPM_AF_TOSPRESENT ((TPM_CAPABILITY_AREA) 4)
+
+//
+// All those structures (section 7.4, 7.5, 7.6) are not normative and
+// thus no definitions here
+//
+// Part 2, section 7.4: TPM_PERMANENT_DATA
+//
+//#define TPM_MIN_COUNTERS 4 // the minimum number of counters is 4
+//#define TPM_DELEGATE_KEY TPM_KEY
+//#define TPM_NUM_PCR 16
+//#define TPM_MAX_NV_WRITE_NOOWNER 64
+//typedef struct tdTPM_PERMANENT_DATA
+//{
+// TPM_STRUCTURE_TAG tag;
+// UINT8 revMajor;
+// UINT8 revMinor;
+// TPM_NONCE tpmProof;
+// TPM_NONCE ekReset;
+// TPM_SECRET ownerAuth;
+// TPM_SECRET operatorAuth;
+// TPM_DIRVALUE authDIR[1];
+// TPM_PUBKEY manuMaintPub;
+// TPM_KEY endorsementKey;
+// TPM_KEY srk;
+// TPM_KEY contextKey;
+// TPM_KEY delegateKey;
+// TPM_COUNTER_VALUE auditMonotonicCounter;
+// TPM_COUNTER_VALUE monitonicCounter[TPM_MIN_COUNTERS];
+// TPM_PCR_ATTRIBUTES pcrAttrib[TPM_NUM_PCR];
+// UINT8 ordinalAuditStatus[];
+// UINT8 *rngState;
+// TPM_FAMILY_TABLE familyTable;
+// TPM_DELEGATE_TABLE delegateTable;
+// UINT32 maxNVBufSize;
+// UINT32 lastFamilyID;
+// UINT32 noOwnerNVWrite;
+// TPM_CMK_DELEGATE restrictDelegate;
+// TPM_DAA_TPM_SEED tpmDAASeed;
+//} TPM_PERMANENT_DATA;
+
+//
+// Part 2, section 7.5: TPM_STCLEAR_DATA
+// available inside TPM only
+//
+//typedef struct tdTPM_STCLEAR_DATA
+//{
+// TPM_STRUCTURE_TAG tag;
+// TPM_NONCE contextNonceKey;
+// TPM_COUNT_ID countID;
+// UINT32 ownerReference;
+// BOOLEAN disableResetLock;
+//} TPM_STCLEAR_DATA;
+
+//
+// Part 2, section 7.6: TPM_STANY_DATA
+// available inside TPM only
+//
+//typedef struct tdTPM_STANY_DATA
+//{
+// TPM_STRUCTURE_TAG tag;
+// TPM_NONCE contextNonceSession;
+// TPM_DIGEST auditDigest;
+// TPM_CURRENT_TICKS currentTicks;
+// UINT32 contextCount;
+// UINT32 contextList[TPM_MIN_SESSION_LIST];
+// TPM_SESSION_DATA sessions[TPM_MIN_SESSIONS];
+//} TPM_STANY_DATA;
+
+//
+// Part 2, section 8: PCR Structures
+//
+
+//
+// Part 2, section 8.1: TPM_PCR_SELECTION
+// Size of pcrSelect[] indicated by sizeOfSelect
+//
+typedef struct tdTPM_PCR_SELECTION
+{
+ UINT16 sizeOfSelect;
+ UINT8 pcrSelect[1];
+} TPM_PCR_SELECTION;
+
+//
+// Part 2, section 8.2: TPM_PCR_COMPOSITE
+// Size of pcrValue[] indicated by valueSize
+//
+typedef struct tdTPM_PCR_COMPOSITE
+{
+ TPM_PCR_SELECTION select;
+ UINT32 valueSize;
+ TPM_PCRVALUE pcrValue[1];
+} TPM_PCR_COMPOSITE;
+
+//
+// Part 2, section 8.3: TPM_PCR_INFO
+//
+typedef struct tdTPM_PCR_INFO
+{
+ TPM_PCR_SELECTION pcrSelection;
+ TPM_COMPOSITE_HASH digestAtRelease;
+ TPM_COMPOSITE_HASH digestAtCreation;
+} TPM_PCR_INFO;
+
+//
+// Part 2, section 8.6: TPM_LOCALITY_SELECTION
+//
+typedef UINT8 TPM_LOCALITY_SELECTION;
+
+#define TPM_LOC_FOUR ((UINT8) 0x10)
+#define TPM_LOC_THREE ((UINT8) 0x08)
+#define TPM_LOC_TWO ((UINT8) 0x04)
+#define TPM_LOC_ONE ((UINT8) 0x02)
+#define TPM_LOC_ZERO ((UINT8) 0x01)
+
+//
+// Part 2, section 8.4: TPM_PCR_INFO_LONG
+//
+typedef struct tdTPM_PCR_INFO_LONG
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_LOCALITY_SELECTION localityAtCreation;
+ TPM_LOCALITY_SELECTION localityAtRelease;
+ TPM_PCR_SELECTION creationPCRSelection;
+ TPM_PCR_SELECTION releasePCRSelection;
+ TPM_COMPOSITE_HASH digestAtCreation;
+ TPM_COMPOSITE_HASH digestAtRelease;
+} TPM_PCR_INFO_LONG;
+
+//
+// Part 2, section 8.5: TPM_PCR_INFO_SHORT
+//
+typedef struct tdTPM_PCR_INFO_SHORT
+{
+ TPM_PCR_SELECTION pcrSelection;
+ TPM_LOCALITY_SELECTION localityAtRelease;
+ TPM_COMPOSITE_HASH digestAtRelease;
+} TPM_PCR_INFO_SHORT;
+
+//
+// Part 2, section 8.8: TPM_PCR_ATTRIBUTES
+//
+typedef struct tdTPM_PCR_ATTRIBUTES
+{
+ BOOLEAN pcrReset;
+ TPM_LOCALITY_SELECTION pcrExtendLocal;
+ TPM_LOCALITY_SELECTION pcrResetLocal;
+} TPM_PCR_ATTRIBUTES;
+
+//
+// Part 2, section 9: Storage Structures
+//
+
+//
+// Part 2, section 9.1: TPM_STORED_DATA
+// [size_is(sealInfoSize)] BYTE* sealInfo;
+// [size_is(encDataSize)] BYTE* encData;
+//
+typedef struct tdTPM_STORED_DATA
+{
+ TPM_STRUCT_VER ver;
+ UINT32 sealInfoSize;
+ UINT8 *sealInfo;
+ UINT32 encDataSize;
+ UINT8 *encData;
+} TPM_STORED_DATA;
+
+//
+// Part 2, section 9.2: TPM_STORED_DATA12
+// [size_is(sealInfoSize)] BYTE* sealInfo;
+// [size_is(encDataSize)] BYTE* encData;
+//
+typedef struct tdTPM_STORED_DATA12
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_ENTITY_TYPE et;
+ UINT32 sealInfoSize;
+ UINT8 *sealInfo;
+ UINT32 encDataSize;
+ UINT8 *encData;
+} TPM_STORED_DATA12;
+
+//
+// Part 2, section 9.3: TPM_SEALED_DATA
+// [size_is(dataSize)] BYTE* data;
+//
+typedef struct tdTPM_SEALED_DATA
+{
+ TPM_PAYLOAD_TYPE payload;
+ TPM_SECRET authData;
+ TPM_NONCE tpmProof;
+ TPM_DIGEST storedDigest;
+ UINT32 dataSize;
+ UINT8 *data;
+} TPM_SEALED_DATA;
+
+//
+// Part 2, section 9.4: TPM_SYMMETRIC_KEY
+// [size_is(size)] BYTE* data;
+//
+typedef struct tdTPM_SYMMETRIC_KEY
+{
+ TPM_ALGORITHM_ID algId;
+ TPM_ENC_SCHEME encScheme;
+ UINT16 dataSize;
+ UINT8 *data;
+} TPM_SYMMETRIC_KEY;
+
+//
+// Part 2, section 9.5: TPM_BOUND_DATA
+//
+typedef struct tdTPM_BOUND_DATA
+{
+ TPM_STRUCT_VER ver;
+ TPM_PAYLOAD_TYPE payload;
+ UINT8 payloadData[1];
+} TPM_BOUND_DATA;
+
+//
+// Part 2 section 10: TPM_KEY complex
+//
+
+//
+// Part 2, section 10.2: TPM_KEY
+// [size_is(encDataSize)] BYTE* encData;
+//
+typedef struct tdTPM_KEY
+{
+ TPM_STRUCT_VER ver;
+ TPM_KEY_USAGE keyUsage;
+ TPM_KEY_FLAGS keyFlags;
+ TPM_AUTH_DATA_USAGE authDataUsage;
+ TPM_KEY_PARMS algorithmParms;
+ UINT32 PCRInfoSize;
+ UINT8 *PCRInfo;
+ TPM_STORE_PUBKEY pubKey;
+ UINT32 encDataSize;
+ UINT8 *encData;
+} TPM_KEY;
+
+//
+// Part 2, section 10.3: TPM_KEY12
+// [size_is(encDataSize)] BYTE* encData;
+//
+typedef struct tdTPM_KEY12
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT16 fill;
+ TPM_KEY_USAGE keyUsage;
+ TPM_KEY_FLAGS keyFlags;
+ TPM_AUTH_DATA_USAGE authDataUsage;
+ TPM_KEY_PARMS algorithmParms;
+ UINT32 PCRInfoSize;
+ UINT8 *PCRInfo;
+ TPM_STORE_PUBKEY pubKey;
+ UINT32 encDataSize;
+ UINT8 *encData;
+} TPM_KEY12;
+
+//
+// Part 2, section 10.7: TPM_STORE_PRIVKEY
+// [size_is(keyLength)] BYTE* key;
+//
+typedef struct tdTPM_STORE_PRIVKEY
+{
+ UINT32 keyLength;
+ UINT8 *key;
+} TPM_STORE_PRIVKEY;
+
+//
+// Part 2, section 10.6: TPM_STORE_ASYMKEY
+//
+typedef struct tdTPM_STORE_ASYMKEY // pos len total
+{
+ TPM_PAYLOAD_TYPE payload; // 0 1 1
+ TPM_SECRET usageAuth; // 1 20 21
+ TPM_SECRET migrationAuth; // 21 20 41
+ TPM_DIGEST pubDataDigest; // 41 20 61
+ TPM_STORE_PRIVKEY privKey; // 61 132-151 193-214
+} TPM_STORE_ASYMKEY;
+
+//
+// Part 2, section 10.8: TPM_MIGRATE_ASYMKEY
+// [size_is(partPrivKeyLen)] BYTE* partPrivKey;
+//
+typedef struct tdTPM_MIGRATE_ASYMKEY // pos len total
+{
+ TPM_PAYLOAD_TYPE payload; // 0 1 1
+ TPM_SECRET usageAuth; // 1 20 21
+ TPM_DIGEST pubDataDigest; // 21 20 41
+ UINT32 partPrivKeyLen; // 41 4 45
+ UINT8 *partPrivKey; // 45 112-127 157-172
+} TPM_MIGRATE_ASYMKEY;
+
+//
+// Part 2, section 10.9: TPM_KEY_CONTROL
+//
+#define TPM_KEY_CONTROL_OWNER_EVICT ((UINT32) 0x00000001)
+#define TPM_CAP_FLAG_STANY 0X0000011D
+
+//
+// Part 2, section 11: Signed Structures
+//
+
+typedef struct tdTPM_CERTIFY_INFO
+{
+ TPM_STRUCT_VER version;
+ TPM_KEY_USAGE keyUsage;
+ TPM_KEY_FLAGS keyFlags;
+ TPM_AUTH_DATA_USAGE authDataUsage;
+ TPM_KEY_PARMS algorithmParms;
+ TPM_DIGEST pubkeyDigest;
+ TPM_NONCE data;
+ BOOLEAN parentPCRStatus;
+ UINT32 PCRInfoSize;
+ UINT8 *PCRInfo;
+} TPM_CERTIFY_INFO;
+
+typedef struct tdTPM_CERTIFY_INFO2
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT8 fill;
+ TPM_PAYLOAD_TYPE payloadType;
+ TPM_KEY_USAGE keyUsage;
+ TPM_KEY_FLAGS keyFlags;
+ TPM_AUTH_DATA_USAGE authDataUsage;
+ TPM_KEY_PARMS algorithmParms;
+ TPM_DIGEST pubkeyDigest;
+ TPM_NONCE data;
+ BOOLEAN parentPCRStatus;
+ UINT32 PCRInfoSize;
+ UINT8 *PCRInfo;
+ UINT32 migrationAuthoritySize;
+ UINT8 *migrationAuthority;
+} TPM_CERTIFY_INFO2;
+
+typedef struct tdTPM_QUOTE_INFO
+{
+ TPM_STRUCT_VER version;
+ UINT8 fixed[4];
+ TPM_COMPOSITE_HASH digestValue;
+ TPM_NONCE externalData;
+} TPM_QUOTE_INFO;
+
+typedef struct tdTPM_QUOTE_INFO2
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT8 fixed[4];
+ TPM_NONCE externalData;
+ TPM_PCR_INFO_SHORT infoShort;
+} TPM_QUOTE_INFO2;
+
+//
+// Part 2, section 12: Identity Structures
+//
+
+typedef struct tdTPM_EK_BLOB
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_EK_TYPE ekType;
+ UINT32 blobSize;
+ UINT8 *blob;
+} TPM_EK_BLOB;
+
+typedef struct tdTPM_EK_BLOB_ACTIVATE
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_SYMMETRIC_KEY sessionKey;
+ TPM_DIGEST idDigest;
+ TPM_PCR_INFO_SHORT pcrInfo;
+} TPM_EK_BLOB_ACTIVATE;
+
+typedef struct tdTPM_EK_BLOB_AUTH
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_SECRET authValue;
+} TPM_EK_BLOB_AUTH;
+
+
+// TPM_CHOSENID_HASH = SHA(identityLabel || privacyCA)
+typedef TPM_DIGEST TPM_CHOSENID_HASH;
+
+typedef struct tdTPM_IDENTITY_CONTENTS
+{
+ TPM_STRUCT_VER ver;
+ UINT32 ordinal;
+ TPM_CHOSENID_HASH labelPrivCADigest;
+ TPM_PUBKEY identityPubKey;
+} TPM_IDENTITY_CONTENTS;
+
+typedef struct tdTPM_IDENTITY_REQ
+{
+ UINT32 asymSize;
+ UINT32 symSize;
+ TPM_KEY_PARMS asymAlgorithm;
+ TPM_KEY_PARMS symAlgorithm;
+ UINT8 *asymBlob;
+ UINT8 *symBlob;
+} TPM_IDENTITY_REQ;
+
+typedef struct tdTPM_IDENTITY_PROOF
+{
+ TPM_STRUCT_VER ver;
+ UINT32 labelSize;
+ UINT32 identityBindingSize;
+ UINT32 endorsementSize;
+ UINT32 platformSize;
+ UINT32 conformanceSize;
+ TPM_PUBKEY identityKey;
+ UINT8 *labelArea;
+ UINT8 *identityBinding;
+ UINT8 *endorsementCredential;
+ UINT8 *platformCredential;
+ UINT8 *conformanceCredential;
+} TPM_IDENTITY_PROOF;
+
+typedef struct tdTPM_ASYM_CA_CONTENTS
+{
+ TPM_SYMMETRIC_KEY sessionKey;
+ TPM_DIGEST idDigest;
+} TPM_ASYM_CA_CONTENTS;
+
+typedef struct tdTPM_SYM_CA_ATTESTATION
+{
+ UINT32 credSize;
+ TPM_KEY_PARMS algorithm;
+ UINT8 *credential;
+} TPM_SYM_CA_ATTESTATION;
+
+//
+// Part 2, section 15: TPM_CURRENT_TICKS
+// Placed here out of order because definitions are used in section 13.
+//
+typedef struct tdTPM_CURRENT_TICKS
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT64 currentTicks;
+ UINT16 tickRate;
+ TPM_NONCE tickNonce;
+} TPM_CURRENT_TICKS;
+
+//
+// Part 2, section 13: Transport structures
+//
+
+#define TPM_TRANSPORT_ENCRYPT ((UINT32)0x00000001)
+#define TPM_TRANSPORT_LOG ((UINT32)0x00000002)
+#define TPM_TRANSPORT_EXCLUSIVE ((UINT32)0x00000004)
+
+typedef struct tdTPM_TRANSPORT_PUBLIC
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_TRANSPORT_ATTRIBUTES transAttributes;
+ TPM_ALGORITHM_ID algId;
+ TPM_ENC_SCHEME encScheme;
+} TPM_TRANSPORT_PUBLIC;
+
+typedef struct tdTPM_TRANSPORT_INTERNAL
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_AUTHDATA authData;
+ TPM_TRANSPORT_PUBLIC transPublic;
+ TPM_TRANSHANDLE transHandle;
+ TPM_NONCE transNonceEven;
+ TPM_DIGEST transDigest;
+} TPM_TRANSPORT_INTERNAL;
+
+typedef struct tdTPM_TRANSPORT_LOG_IN
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DIGEST parameters;
+ TPM_DIGEST pubKeyHash;
+} TPM_TRANSPORT_LOG_IN;
+
+typedef struct tdTPM_TRANSPORT_LOG_OUT
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_CURRENT_TICKS currentTicks;
+ TPM_DIGEST parameters;
+ TPM_MODIFIER_INDICATOR locality;
+} TPM_TRANSPORT_LOG_OUT;
+
+typedef struct tdTPM_TRANSPORT_AUTH
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_AUTHDATA authData;
+} TPM_TRANSPORT_AUTH;
+
+//
+// Part 2, section 14: Audit Structures
+//
+
+typedef struct tdTPM_AUDIT_EVENT_IN
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DIGEST inputParms;
+ TPM_COUNTER_VALUE auditCount;
+} TPM_AUDIT_EVENT_IN;
+
+typedef struct tdTPM_AUDIT_EVENT_OUT
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_COMMAND_CODE ordinal;
+ TPM_DIGEST outputParms;
+ TPM_COUNTER_VALUE auditCount;
+ TPM_RESULT returnCode;
+} TPM_AUDIT_EVENT_OUT;
+
+//
+// Part 2, section 16: Return Codes
+//
+#define TPM_BASE (EFI_MAX_BIT + (EFI_MAX_BIT >> 1))
+
+#ifndef TPM_BASE
+ #error "TPM Error Codes require definition of TPM_BASE"
+#endif
+
+#define TPM_VENDOR_ERROR TPM_Vendor_Specific32
+#define TPM_NON_FATAL 0x00000800
+
+#define TPM_SUCCESS ((TPM_RESULT) TPM_BASE)
+#define TPM_AUTHFAIL ((TPM_RESULT) (TPM_BASE + 1))
+#define TPM_BADINDEX ((TPM_RESULT) (TPM_BASE + 2))
+#define TPM_BAD_PARAMETER ((TPM_RESULT) (TPM_BASE + 3))
+#define TPM_AUDITFAILURE ((TPM_RESULT) (TPM_BASE + 4))
+#define TPM_CLEAR_DISABLED ((TPM_RESULT) (TPM_BASE + 5))
+#define TPM_DEACTIVATED ((TPM_RESULT) (TPM_BASE + 6))
+#define TPM_DISABLED ((TPM_RESULT) (TPM_BASE + 7))
+#define TPM_DISABLED_CMD ((TPM_RESULT) (TPM_BASE + 8))
+#define TPM_FAIL ((TPM_RESULT) (TPM_BASE + 9))
+#define TPM_BAD_ORDINAL ((TPM_RESULT) (TPM_BASE + 10))
+#define TPM_INSTALL_DISABLED ((TPM_RESULT) (TPM_BASE + 11))
+#define TPM_INVALID_KEYHANDLE ((TPM_RESULT) (TPM_BASE + 12))
+#define TPM_KEYNOTFOUND ((TPM_RESULT) (TPM_BASE + 13))
+#define TPM_INAPPROPRIATE_ENC ((TPM_RESULT) (TPM_BASE + 14))
+#define TPM_MIGRATEFAIL ((TPM_RESULT) (TPM_BASE + 15))
+#define TPM_INVALID_PCR_INFO ((TPM_RESULT) (TPM_BASE + 16))
+#define TPM_NOSPACE ((TPM_RESULT) (TPM_BASE + 17))
+#define TPM_NOSRK ((TPM_RESULT) (TPM_BASE + 18))
+#define TPM_NOTSEALED_BLOB ((TPM_RESULT) (TPM_BASE + 19))
+#define TPM_OWNER_SET ((TPM_RESULT) (TPM_BASE + 20))
+#define TPM_RESOURCES ((TPM_RESULT) (TPM_BASE + 21))
+#define TPM_SHORTRANDOM ((TPM_RESULT) (TPM_BASE + 22))
+#define TPM_SIZE ((TPM_RESULT) (TPM_BASE + 23))
+#define TPM_WRONGPCRVAL ((TPM_RESULT) (TPM_BASE + 24))
+#define TPM_BAD_PARAM_SIZE ((TPM_RESULT) (TPM_BASE + 25))
+#define TPM_SHA_THREAD ((TPM_RESULT) (TPM_BASE + 26))
+#define TPM_SHA_ERROR ((TPM_RESULT) (TPM_BASE + 27))
+#define TPM_FAILEDSELFTEST ((TPM_RESULT) (TPM_BASE + 28))
+#define TPM_AUTH2FAIL ((TPM_RESULT) (TPM_BASE + 29))
+#define TPM_BADTAG ((TPM_RESULT) (TPM_BASE + 30))
+#define TPM_IOERROR ((TPM_RESULT) (TPM_BASE + 31))
+#define TPM_ENCRYPT_ERROR ((TPM_RESULT) (TPM_BASE + 32))
+#define TPM_DECRYPT_ERROR ((TPM_RESULT) (TPM_BASE + 33))
+#define TPM_INVALID_AUTHHANDLE ((TPM_RESULT) (TPM_BASE + 34))
+#define TPM_NO_ENDORSEMENT ((TPM_RESULT) (TPM_BASE + 35))
+#define TPM_INVALID_KEYUSAGE ((TPM_RESULT) (TPM_BASE + 36))
+#define TPM_WRONG_ENTITYTYPE ((TPM_RESULT) (TPM_BASE + 37))
+#define TPM_INVALID_POSTINIT ((TPM_RESULT) (TPM_BASE + 38))
+#define TPM_INAPPROPRIATE_SIG ((TPM_RESULT) (TPM_BASE + 39))
+#define TPM_BAD_KEY_PROPERTY ((TPM_RESULT) (TPM_BASE + 40))
+#define TPM_BAD_MIGRATION ((TPM_RESULT) (TPM_BASE + 41))
+#define TPM_BAD_SCHEME ((TPM_RESULT) (TPM_BASE + 42))
+#define TPM_BAD_DATASIZE ((TPM_RESULT) (TPM_BASE + 43))
+#define TPM_BAD_MODE ((TPM_RESULT) (TPM_BASE + 44))
+#define TPM_BAD_PRESENCE ((TPM_RESULT) (TPM_BASE + 45))
+#define TPM_BAD_VERSION ((TPM_RESULT) (TPM_BASE + 46))
+#define TPM_NO_WRAP_TRANSPORT ((TPM_RESULT) (TPM_BASE + 47))
+#define TPM_AUDITFAIL_UNSUCCESSFUL ((TPM_RESULT) (TPM_BASE + 48))
+#define TPM_AUDITFAIL_SUCCESSFUL ((TPM_RESULT) (TPM_BASE + 49))
+#define TPM_NOTRESETABLE ((TPM_RESULT) (TPM_BASE + 50))
+#define TPM_NOTLOCAL ((TPM_RESULT) (TPM_BASE + 51))
+#define TPM_BAD_TYPE ((TPM_RESULT) (TPM_BASE + 52))
+#define TPM_INVALID_RESOURCE ((TPM_RESULT) (TPM_BASE + 53))
+#define TPM_NOTFIPS ((TPM_RESULT) (TPM_BASE + 54))
+#define TPM_INVALID_FAMILY ((TPM_RESULT) (TPM_BASE + 55))
+#define TPM_NO_NV_PERMISSION ((TPM_RESULT) (TPM_BASE + 56))
+#define TPM_REQUIRES_SIGN ((TPM_RESULT) (TPM_BASE + 57))
+#define TPM_KEY_NOTSUPPORTED ((TPM_RESULT) (TPM_BASE + 58))
+#define TPM_AUTH_CONFLICT ((TPM_RESULT) (TPM_BASE + 59))
+#define TPM_AREA_LOCKED ((TPM_RESULT) (TPM_BASE + 60))
+#define TPM_BAD_LOCALITY ((TPM_RESULT) (TPM_BASE + 61))
+#define TPM_READ_ONLY ((TPM_RESULT) (TPM_BASE + 62))
+#define TPM_PER_NOWRITE ((TPM_RESULT) (TPM_BASE + 63))
+#define TPM_FAMILYCOUNT ((TPM_RESULT) (TPM_BASE + 64))
+#define TPM_WRITE_LOCKED ((TPM_RESULT) (TPM_BASE + 65))
+#define TPM_BAD_ATTRIBUTES ((TPM_RESULT) (TPM_BASE + 66))
+#define TPM_INVALID_STRUCTURE ((TPM_RESULT) (TPM_BASE + 67))
+#define TPM_KEY_OWNER_CONTROL ((TPM_RESULT) (TPM_BASE + 68))
+#define TPM_BAD_COUNTER ((TPM_RESULT) (TPM_BASE + 69))
+#define TPM_NOT_FULLWRITE ((TPM_RESULT) (TPM_BASE + 70))
+#define TPM_CONTEXT_GAP ((TPM_RESULT) (TPM_BASE + 71))
+#define TPM_MAXNVWRITES ((TPM_RESULT) (TPM_BASE + 72))
+#define TPM_NOOPERATOR ((TPM_RESULT) (TPM_BASE + 73))
+#define TPM_RESOURCEMISSING ((TPM_RESULT) (TPM_BASE + 74))
+#define TPM_DELEGATE_LOCK ((TPM_RESULT) (TPM_BASE + 75))
+#define TPM_DELEGATE_FAMILY ((TPM_RESULT) (TPM_BASE + 76))
+#define TPM_DELEGATE_ADMIN ((TPM_RESULT) (TPM_BASE + 77))
+#define TPM_TRANSPORT_NOTEXCLUSIVE ((TPM_RESULT) (TPM_BASE + 78))
+#define TPM_OWNER_CONTROL ((TPM_RESULT) (TPM_BASE + 79))
+#define TPM_DAA_RESOURCES ((TPM_RESULT) (TPM_BASE + 80))
+#define TPM_DAA_INPUT_DATA0 ((TPM_RESULT) (TPM_BASE + 81))
+#define TPM_DAA_INPUT_DATA1 ((TPM_RESULT) (TPM_BASE + 82))
+#define TPM_DAA_ISSUER_SETTINGS ((TPM_RESULT) (TPM_BASE + 83))
+#define TPM_DAA_TPM_SETTINGS ((TPM_RESULT) (TPM_BASE + 84))
+#define TPM_DAA_STAGE ((TPM_RESULT) (TPM_BASE + 85))
+#define TPM_DAA_ISSUER_VALIDITY ((TPM_RESULT) (TPM_BASE + 86))
+#define TPM_DAA_WRONG_W ((TPM_RESULT) (TPM_BASE + 87))
+#define TPM_BAD_HANDLE ((TPM_RESULT) (TPM_BASE + 88))
+#define TPM_BAD_DELEGATE ((TPM_RESULT) (TPM_BASE + 89))
+#define TPM_BADCONTEXT ((TPM_RESULT) (TPM_BASE + 90))
+#define TPM_TOOMANYCONTEXTS ((TPM_RESULT) (TPM_BASE + 91))
+#define TPM_MA_TICKET_SIGNATURE ((TPM_RESULT) (TPM_BASE + 92))
+#define TPM_MA_DESTINATION ((TPM_RESULT) (TPM_BASE + 93))
+#define TPM_MA_SOURCE ((TPM_RESULT) (TPM_BASE + 94))
+#define TPM_MA_AUTHORITY ((TPM_RESULT) (TPM_BASE + 95))
+#define TPM_PERMANENTEK ((TPM_RESULT) (TPM_BASE + 97))
+#define TPM_BAD_SIGNATURE ((TPM_RESULT) (TPM_BASE + 98))
+#define TPM_NOCONTEXTSPACE ((TPM_RESULT) (TPM_BASE + 99))
+
+#define TPM_RETRY ((TPM_RESULT) (TPM_BASE + TPM_NON_FATAL))
+#define TPM_NEEDS_SELFTEST ((TPM_RESULT) (TPM_BASE + TPM_NON_FATAL + 1))
+#define TPM_DOING_SELFTEST ((TPM_RESULT) (TPM_BASE + TPM_NON_FATAL + 2))
+#define TPM_DEFEND_LOCK_RUNNING ((TPM_RESULT) (TPM_BASE + TPM_NON_FATAL + 3))
+
+//
+// Part 2, section 17: Ordinals
+//
+// Ordinals are 32 bit values. The upper byte contains values that serve as
+// flag indicators, the next byte contains values indicating what committee
+// designated the ordinal, and the final two bytes contain the Command
+// Ordinal Index.
+// 3 2 1
+// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// |P|C|V| Reserved| Purview | Command Ordinal Index |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+//
+// Where:
+//
+// * P is Protected/Unprotected command. When 0 the command is a Protected
+// command, when 1 the command is an Unprotected command.
+//
+// * C is Non-Connection/Connection related command. When 0 this command
+// passes through to either the protected (TPM) or unprotected (TSS)
+// components.
+//
+// * V is TPM/Vendor command. When 0 the command is TPM defined, when 1 the
+// command is vendor defined.
+//
+// * All reserved area bits are set to 0.
+//
+#define TPM_ORD_ActivateIdentity ((TPM_COMMAND_CODE) 0x0000007A)
+#define TPM_ORD_AuthorizeMigrationKey ((TPM_COMMAND_CODE) 0x0000002B)
+#define TPM_ORD_CertifyKey ((TPM_COMMAND_CODE) 0x00000032)
+#define TPM_ORD_CertifyKey2 ((TPM_COMMAND_CODE) 0x00000033)
+#define TPM_ORD_CertifySelfTest ((TPM_COMMAND_CODE) 0x00000052)
+#define TPM_ORD_ChangeAuth ((TPM_COMMAND_CODE) 0x0000000C)
+#define TPM_ORD_ChangeAuthAsymFinish ((TPM_COMMAND_CODE) 0x0000000F)
+#define TPM_ORD_ChangeAuthAsymStart ((TPM_COMMAND_CODE) 0x0000000E)
+#define TPM_ORD_ChangeAuthOwner ((TPM_COMMAND_CODE) 0x00000010)
+#define TPM_ORD_CMK_ApproveMA ((TPM_COMMAND_CODE) 0x0000001D)
+#define TPM_ORD_CMK_ConvertMigration ((TPM_COMMAND_CODE) 0x00000024)
+#define TPM_ORD_CMK_CreateBlob ((TPM_COMMAND_CODE) 0x0000001B)
+#define TPM_ORD_CMK_CreateKey ((TPM_COMMAND_CODE) 0x00000013)
+#define TPM_ORD_CMK_CreateTicket ((TPM_COMMAND_CODE) 0x00000012)
+#define TPM_ORD_CMK_SetRestrictions ((TPM_COMMAND_CODE) 0x0000001C)
+#define TPM_ORD_ContinueSelfTest ((TPM_COMMAND_CODE) 0x00000053)
+#define TPM_ORD_ConvertMigrationBlob ((TPM_COMMAND_CODE) 0x0000002A)
+#define TPM_ORD_CreateCounter ((TPM_COMMAND_CODE) 0x000000DC)
+#define TPM_ORD_CreateEndorsementKeyPair ((TPM_COMMAND_CODE) 0x00000078)
+#define TPM_ORD_CreateMaintenanceArchive ((TPM_COMMAND_CODE) 0x0000002C)
+#define TPM_ORD_CreateMigrationBlob ((TPM_COMMAND_CODE) 0x00000028)
+#define TPM_ORD_CreateRevocableEK ((TPM_COMMAND_CODE) 0x0000007F)
+#define TPM_ORD_CreateWrapKey ((TPM_COMMAND_CODE) 0x0000001F)
+#define TPM_ORD_DAA_JOIN ((TPM_COMMAND_CODE) 0x00000029)
+#define TPM_ORD_DAA_SIGN ((TPM_COMMAND_CODE) 0x00000031)
+#define TPM_ORD_Delegate_CreateKeyDelegation ((TPM_COMMAND_CODE) 0x000000D4)
+#define TPM_ORD_Delegate_CreateOwnerDelegation ((TPM_COMMAND_CODE) 0x000000D5)
+#define TPM_ORD_Delegate_LoadOwnerDelegation ((TPM_COMMAND_CODE) 0x000000D8)
+#define TPM_ORD_Delegate_Manage ((TPM_COMMAND_CODE) 0x000000D2)
+#define TPM_ORD_Delegate_ReadTable ((TPM_COMMAND_CODE) 0x000000DB)
+#define TPM_ORD_Delegate_UpdateVerification ((TPM_COMMAND_CODE) 0x000000D1)
+#define TPM_ORD_Delegate_VerifyDelegation ((TPM_COMMAND_CODE) 0x000000D6)
+#define TPM_ORD_DirRead ((TPM_COMMAND_CODE) 0x0000001A)
+#define TPM_ORD_DirWriteAuth ((TPM_COMMAND_CODE) 0x00000019)
+#define TPM_ORD_DisableForceClear ((TPM_COMMAND_CODE) 0x0000005E)
+#define TPM_ORD_DisableOwnerClear ((TPM_COMMAND_CODE) 0x0000005C)
+#define TPM_ORD_DisablePubekRead ((TPM_COMMAND_CODE) 0x0000007E)
+#define TPM_ORD_DSAP ((TPM_COMMAND_CODE) 0x00000011)
+#define TPM_ORD_EstablishTransport ((TPM_COMMAND_CODE) 0x000000E6)
+#define TPM_ORD_EvictKey ((TPM_COMMAND_CODE) 0x00000022)
+#define TPM_ORD_ExecuteTransport ((TPM_COMMAND_CODE) 0x000000E7)
+#define TPM_ORD_Extend ((TPM_COMMAND_CODE) 0x00000014)
+#define TPM_ORD_FieldUpgrade ((TPM_COMMAND_CODE) 0x000000AA)
+#define TPM_ORD_FlushSpecific ((TPM_COMMAND_CODE) 0x000000BA)
+#define TPM_ORD_ForceClear ((TPM_COMMAND_CODE) 0x0000005D)
+#define TPM_ORD_GetAuditDigest ((TPM_COMMAND_CODE) 0x00000085)
+#define TPM_ORD_GetAuditDigestSigned ((TPM_COMMAND_CODE) 0x00000086)
+#define TPM_ORD_GetAuditEvent ((TPM_COMMAND_CODE) 0x00000082)
+#define TPM_ORD_GetAuditEventSigned ((TPM_COMMAND_CODE) 0x00000083)
+#define TPM_ORD_GetCapability ((TPM_COMMAND_CODE) 0x00000065)
+#define TPM_ORD_GetCapabilityOwner ((TPM_COMMAND_CODE) 0x00000066)
+#define TPM_ORD_GetCapabilitySigned ((TPM_COMMAND_CODE) 0x00000064)
+#define TPM_ORD_GetOrdinalAuditStatus ((TPM_COMMAND_CODE) 0x0000008C)
+#define TPM_ORD_GetPubKey ((TPM_COMMAND_CODE) 0x00000021)
+#define TPM_ORD_GetRandom ((TPM_COMMAND_CODE) 0x00000046)
+#define TPM_ORD_GetTestResult ((TPM_COMMAND_CODE) 0x00000054)
+#define TPM_ORD_GetTicks ((TPM_COMMAND_CODE) 0x000000F1)
+#define TPM_ORD_IncrementCounter ((TPM_COMMAND_CODE) 0x000000DD)
+#define TPM_ORD_Init ((TPM_COMMAND_CODE) 0x00000097)
+#define TPM_ORD_KeyControlOwner ((TPM_COMMAND_CODE) 0x00000023)
+#define TPM_ORD_KillMaintenanceFeature ((TPM_COMMAND_CODE) 0x0000002E)
+#define TPM_ORD_LoadAuthContext ((TPM_COMMAND_CODE) 0x000000B7)
+#define TPM_ORD_LoadContext ((TPM_COMMAND_CODE) 0x000000B9)
+#define TPM_ORD_LoadKey ((TPM_COMMAND_CODE) 0x00000020)
+#define TPM_ORD_LoadKey2 ((TPM_COMMAND_CODE) 0x00000041)
+#define TPM_ORD_LoadKeyContext ((TPM_COMMAND_CODE) 0x000000B5)
+#define TPM_ORD_LoadMaintenanceArchive ((TPM_COMMAND_CODE) 0x0000002D)
+#define TPM_ORD_LoadManuMaintPub ((TPM_COMMAND_CODE) 0x0000002F)
+#define TPM_ORD_MakeIdentity ((TPM_COMMAND_CODE) 0x00000079)
+#define TPM_ORD_MigrateKey ((TPM_COMMAND_CODE) 0x00000025)
+#define TPM_ORD_NV_DefineSpace ((TPM_COMMAND_CODE) 0x000000CC)
+#define TPM_ORD_NV_ReadValue ((TPM_COMMAND_CODE) 0x000000CF)
+#define TPM_ORD_NV_ReadValueAuth ((TPM_COMMAND_CODE) 0x000000D0)
+#define TPM_ORD_NV_WriteValue ((TPM_COMMAND_CODE) 0x000000CD)
+#define TPM_ORD_NV_WriteValueAuth ((TPM_COMMAND_CODE) 0x000000CE)
+#define TPM_ORD_OIAP ((TPM_COMMAND_CODE) 0x0000000A)
+#define TPM_ORD_OSAP ((TPM_COMMAND_CODE) 0x0000000B)
+#define TPM_ORD_OwnerClear ((TPM_COMMAND_CODE) 0x0000005B)
+#define TPM_ORD_OwnerReadInternalPub ((TPM_COMMAND_CODE) 0x00000081)
+#define TPM_ORD_OwnerReadPubek ((TPM_COMMAND_CODE) 0x0000007D)
+#define TPM_ORD_OwnerSetDisable ((TPM_COMMAND_CODE) 0x0000006E)
+#define TPM_ORD_PCR_Reset ((TPM_COMMAND_CODE) 0x000000C8)
+#define TPM_ORD_PcrRead ((TPM_COMMAND_CODE) 0x00000015)
+#define TPM_ORD_PhysicalDisable ((TPM_COMMAND_CODE) 0x00000070)
+#define TPM_ORD_PhysicalEnable ((TPM_COMMAND_CODE) 0x0000006F)
+#define TPM_ORD_PhysicalSetDeactivated ((TPM_COMMAND_CODE) 0x00000072)
+#define TPM_ORD_Quote ((TPM_COMMAND_CODE) 0x00000016)
+#define TPM_ORD_Quote2 ((TPM_COMMAND_CODE) 0x0000003E)
+#define TPM_ORD_ReadCounter ((TPM_COMMAND_CODE) 0x000000DE)
+#define TPM_ORD_ReadManuMaintPub ((TPM_COMMAND_CODE) 0x00000030)
+#define TPM_ORD_ReadPubek ((TPM_COMMAND_CODE) 0x0000007C)
+#define TPM_ORD_ReleaseCounter ((TPM_COMMAND_CODE) 0x000000DF)
+#define TPM_ORD_ReleaseCounterOwner ((TPM_COMMAND_CODE) 0x000000E0)
+#define TPM_ORD_ReleaseTransportSigned ((TPM_COMMAND_CODE) 0x000000E8)
+#define TPM_ORD_Reset ((TPM_COMMAND_CODE) 0x0000005A)
+#define TPM_ORD_ResetLockValue ((TPM_COMMAND_CODE) 0x00000040)
+#define TPM_ORD_RevokeTrust ((TPM_COMMAND_CODE) 0x00000080)
+#define TPM_ORD_SaveAuthContext ((TPM_COMMAND_CODE) 0x000000B6)
+#define TPM_ORD_SaveContext ((TPM_COMMAND_CODE) 0x000000B8)
+#define TPM_ORD_SaveKeyContext ((TPM_COMMAND_CODE) 0x000000B4)
+#define TPM_ORD_SaveState ((TPM_COMMAND_CODE) 0x00000098)
+#define TPM_ORD_Seal ((TPM_COMMAND_CODE) 0x00000017)
+#define TPM_ORD_Sealx ((TPM_COMMAND_CODE) 0x0000003D)
+#define TPM_ORD_SelfTestFull ((TPM_COMMAND_CODE) 0x00000050)
+#define TPM_ORD_SetCapability ((TPM_COMMAND_CODE) 0x0000003F)
+#define TPM_ORD_SetOperatorAuth ((TPM_COMMAND_CODE) 0x00000074)
+#define TPM_ORD_SetOrdinalAuditStatus ((TPM_COMMAND_CODE) 0x0000008D)
+#define TPM_ORD_SetOwnerInstall ((TPM_COMMAND_CODE) 0x00000071)
+#define TPM_ORD_SetOwnerPointer ((TPM_COMMAND_CODE) 0x00000075)
+#define TPM_ORD_SetRedirection ((TPM_COMMAND_CODE) 0x0000009A)
+#define TPM_ORD_SetTempDeactivated ((TPM_COMMAND_CODE) 0x00000073)
+#define TPM_ORD_SHA1Complete ((TPM_COMMAND_CODE) 0x000000A2)
+#define TPM_ORD_SHA1CompleteExtend ((TPM_COMMAND_CODE) 0x000000A3)
+#define TPM_ORD_SHA1Start ((TPM_COMMAND_CODE) 0x000000A0)
+#define TPM_ORD_SHA1Update ((TPM_COMMAND_CODE) 0x000000A1)
+#define TPM_ORD_Sign ((TPM_COMMAND_CODE) 0x0000003C)
+#define TPM_ORD_Startup ((TPM_COMMAND_CODE) 0x00000099)
+#define TPM_ORD_StirRandom ((TPM_COMMAND_CODE) 0x00000047)
+#define TPM_ORD_TakeOwnership ((TPM_COMMAND_CODE) 0x0000000D)
+#define TPM_ORD_Terminate_Handle ((TPM_COMMAND_CODE) 0x00000096)
+#define TPM_ORD_TickStampBlob ((TPM_COMMAND_CODE) 0x000000F2)
+#define TPM_ORD_UnBind ((TPM_COMMAND_CODE) 0x0000001E)
+#define TPM_ORD_Unseal ((TPM_COMMAND_CODE) 0x00000018)
+#define TSC_ORD_PhysicalPresence ((TPM_COMMAND_CODE) 0x4000000A)
+#define TSC_ORD_ResetEstablishmentBit ((TPM_COMMAND_CODE) 0x4000000B)
+
+//
+// Part 2, section 18: Context structures
+//
+
+typedef struct tdTPM_CONTEXT_BLOB
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_RESOURCE_TYPE resourceType;
+ TPM_HANDLE handle;
+ UINT8 label[16];
+ UINT32 contextCount;
+ TPM_DIGEST integrityDigest;
+ UINT32 additionalSize;
+ UINT8 *additionalData;
+ UINT32 sensitiveSize;
+ UINT8 *sensitiveData;
+} TPM_CONTEXT_BLOB;
+
+typedef struct tdTPM_CONTEXT_SENSITIVE
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_NONCE contextNonce;
+ UINT32 internalSize;
+ UINT8 *internalData;
+} TPM_CONTEXT_SENSITIVE;
+
+//
+// Part 2, section 19: NV Structures
+//
+
+#define TPM_NV_INDEX_LOCK ((UINT32)0xffffffff)
+#define TPM_NV_INDEX0 ((UINT32)0x00000000)
+#define TPM_NV_INDEX_DIR ((UINT32)0x10000001)
+#define TPM_NV_INDEX_EKCert ((UINT32)0x0000f000)
+#define TPM_NV_INDEX_TPM_CC ((UINT32)0x0000f001)
+#define TPM_NV_INDEX_PlatformCert ((UINT32)0x0000f002)
+#define TPM_NV_INDEX_Platform_CC ((UINT32)0x0000f003)
+// The following define ranges of reserved indices.
+#define TPM_NV_INDEX_TSS_BASE ((UINT32)0x00011100)
+#define TPM_NV_INDEX_PC_BASE ((UINT32)0x00011200)
+#define TPM_NV_INDEX_SERVER_BASE ((UINT32)0x00011300)
+#define TPM_NV_INDEX_MOBILE_BASE ((UINT32)0x00011400)
+#define TPM_NV_INDEX_PERIPHERAL_BASE ((UINT32)0x00011500)
+#define TPM_NV_INDEX_GROUP_RESV_BASE ((UINT32)0x00010000)
+
+typedef UINT32 TPM_NV_PER_ATTRIBUTES;
+// The typedefs TPM_NV_PER_ATTRIBUTES (not present in TPM 1.2 Spec. have been added
+// and structure fields that were to hold the following values
+#define TPM_NV_PER_READ_STCLEAR (((UINT32)1) << 31)
+#define TPM_NV_PER_AUTHREAD (((UINT32)1) << 18)
+#define TPM_NV_PER_OWNERREAD (((UINT32)1) << 17)
+#define TPM_NV_PER_PPREAD (((UINT32)1) << 16)
+#define TPM_NV_PER_GLOBALLOCK (((UINT32)1) << 15)
+#define TPM_NV_PER_WRITE_STCLEAR (((UINT32)1) << 14)
+#define TPM_NV_PER_WRITEDEFINE (((UINT32)1) << 13)
+#define TPM_NV_PER_WRITEALL (((UINT32)1) << 12)
+#define TPM_NV_PER_AUTHWRITE (((UINT32)1) << 2)
+#define TPM_NV_PER_OWNERWRITE (((UINT32)1) << 1)
+#define TPM_NV_PER_PPWRITE (((UINT32)1) << 0)
+
+typedef struct tdTPM_NV_ATTRIBUTES
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_NV_PER_ATTRIBUTES attributes;
+} TPM_NV_ATTRIBUTES;
+
+
+typedef struct tdTPM_NV_DATA_PUBLIC
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_NV_INDEX nvIndex;
+ TPM_PCR_INFO_SHORT pcrInfoRead;
+ TPM_PCR_INFO_SHORT pcrInfoWrite;
+ TPM_NV_ATTRIBUTES permission;
+ BOOLEAN bReadSTClear;
+ BOOLEAN bWriteSTClear;
+ BOOLEAN bWriteDefine;
+ UINT32 dataSize;
+} TPM_NV_DATA_PUBLIC;
+
+
+
+// Internal to TPM:
+//typedef struct tdTPM_NV_DATA_SENSITIVE
+//{
+// TPM_STRUCTURE_TAG tag;
+// TPM_NV_DATA_PUBLIC pubInfo;
+// TPM_AUTHDATA authValue;
+// UINT8 *data;
+//} TPM_NV_DATA_SENSITIVE;
+
+
+//
+// Part 2, section 20: Delegation
+//
+
+//
+// Part 2, section 20.3: Owner Permissions Settings for per1 bits
+//
+#define TPM_DELEGATE_SetOrdinalAuditStatus (((UINT32)1) << 30)
+#define TPM_DELEGATE_DirWriteAuth (((UINT32)1) << 29)
+#define TPM_DELEGATE_CMK_ApproveMA (((UINT32)1) << 28)
+#define TPM_DELEGATE_CMK_CreateTicket (((UINT32)1) << 26)
+#define TPM_DELEGATE_Delegate_LoadOwnerDelegation (((UINT32)1) << 24)
+#define TPM_DELEGATE_DAA_Join (((UINT32)1) << 23)
+#define TPM_DELEGATE_AuthorizeMigrationKey (((UINT32)1) << 22)
+#define TPM_DELEGATE_CreateMaintenanceArchive (((UINT32)1) << 21)
+#define TPM_DELEGATE_LoadMaintenanceArchive (((UINT32)1) << 20)
+#define TPM_DELEGATE_KillMaintenanceFeature (((UINT32)1) << 19)
+#define TPM_DELEGATE_OwnerReadInteralPub (((UINT32)1) << 18)
+#define TPM_DELEGATE_ResetLockValue (((UINT32)1) << 17)
+#define TPM_DELEGATE_OwnerClear (((UINT32)1) << 16)
+#define TPM_DELEGATE_DisableOwnerClear (((UINT32)1) << 15)
+#define TPM_DELEGATE_OwnerSetDisable (((UINT32)1) << 13)
+#define TPM_DELEGATE_SetCapability (((UINT32)1) << 12)
+#define TPM_DELEGATE_MakeIdentity (((UINT32)1) << 11)
+#define TPM_DELEGATE_ActivateIdentity (((UINT32)1) << 10)
+#define TPM_DELEGATE_OwnerReadPubek (((UINT32)1) << 9)
+#define TPM_DELEGATE_DisablePubekRead (((UINT32)1) << 8)
+#define TPM_DELEGATE_SetRedirection (((UINT32)1) << 7)
+#define TPM_DELEGATE_FieldUpgrade (((UINT32)1) << 6)
+#define TPM_DELEGATE_Delegate_UpdateVerification (((UINT32)1) << 5)
+#define TPM_DELEGATE_CreateCounter (((UINT32)1) << 4)
+#define TPM_DELEGATE_ReleaseCounterOwner (((UINT32)1) << 3)
+#define TPM_DELEGATE_DelegateManage (((UINT32)1) << 2)
+#define TPM_DELEGATE_Delegate_CreateOwnerDelegation (((UINT32)1) << 1)
+#define TPM_DELEGATE_DAA_Sign (((UINT32)1) << 0)
+
+//
+// Part 2, section 20.3: Key Permissions Settings for per1 bits
+//
+#define TPM_KEY_DELEGATE_CMK_ConvertMigration (((UINT32)1) << 28)
+#define TPM_KEY_DELEGATE_TickStampBlob (((UINT32)1) << 27)
+#define TPM_KEY_DELEGATE_ChangeAuthAsymStart (((UINT32)1) << 26)
+#define TPM_KEY_DELEGATE_ChangeAuthAsymFinish (((UINT32)1) << 25)
+#define TPM_KEY_DELEGATE_CMK_CreateKey (((UINT32)1) << 24)
+#define TPM_KEY_DELEGATE_MigrateKey (((UINT32)1) << 23)
+#define TPM_KEY_DELEGATE_LoadKey2 (((UINT32)1) << 22)
+#define TPM_KEY_DELEGATE_EstablishTransport (((UINT32)1) << 21)
+#define TPM_KEY_DELEGATE_ReleaseTransportSigned (((UINT32)1) << 20)
+#define TPM_KEY_DELEGATE_Quote2 (((UINT32)1) << 19)
+#define TPM_KEY_DELEGATE_Sealx (((UINT32)1) << 18)
+#define TPM_KEY_DELEGATE_MakeIdentity (((UINT32)1) << 17)
+#define TPM_KEY_DELEGATE_ActivateIdentity (((UINT32)1) << 16)
+#define TPM_KEY_DELEGATE_GetAuditDigestSigned (((UINT32)1) << 15)
+#define TPM_KEY_DELEGATE_Sign (((UINT32)1) << 14)
+#define TPM_KEY_DELEGATE_CertifyKey2 (((UINT32)1) << 13)
+#define TPM_KEY_DELEGATE_CertifyKey (((UINT32)1) << 12)
+#define TPM_KEY_DELEGATE_CreateWrapKey (((UINT32)1) << 11)
+#define TPM_KEY_DELEGATE_CMK_CreateBlob (((UINT32)1) << 10)
+#define TPM_KEY_DELEGATE_CreateMigrationBlob (((UINT32)1) << 9)
+#define TPM_KEY_DELEGATE_ConvertMigrationBlob (((UINT32)1) << 8)
+#define TPM_KEY_DELEGATE_CreateKeyDelegation (((UINT32)1) << 7)
+#define TPM_KEY_DELEGATE_ChangeAuth (((UINT32)1) << 6)
+#define TPM_KEY_DELEGATE_GetPubKey (((UINT32)1) << 5)
+#define TPM_KEY_DELEGATE_UnBind (((UINT32)1) << 4)
+#define TPM_KEY_DELEGATE_Quote (((UINT32)1) << 3)
+#define TPM_KEY_DELEGATE_Unseal (((UINT32)1) << 2)
+#define TPM_KEY_DELEGATE_Seal (((UINT32)1) << 1)
+#define TPM_KEY_DELEGATE_LoadKey (((UINT32)1) << 0)
+
+#define TPM_FAMILY_CREATE ((UINT32)0x00000001)
+#define TPM_FAMILY_ENABLE ((UINT32)0x00000002)
+#define TPM_FAMILY_ADMIN ((UINT32)0x00000003)
+#define TPM_FAMILY_INVALIDATE ((UINT32)0x00000004)
+
+#define TPM_FAMFLAG_DELEGATE_ADMIN_LOCK (((UINT32)1) << 1)
+#define TPM_FAMFLAG_ENABLE (((UINT32)1) << 0)
+
+typedef struct tdTPM_FAMILY_LABEL
+{
+ UINT8 label;
+} TPM_FAMILY_LABEL;
+
+typedef struct tdTPM_FAMILY_TABLE_ENTRY
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_FAMILY_LABEL label;
+ TPM_FAMILY_ID familyID;
+ TPM_FAMILY_VERIFICATION verificationCount;
+ TPM_FAMILY_FLAGS flags;
+} TPM_FAMILY_TABLE_ENTRY;
+
+#define TPM_FAMILY_TABLE_ENTRY_MIN 8
+//typedef struct tdTPM_FAMILY_TABLE
+//{
+// TPM_FAMILY_TABLE_ENTRY FamTableRow[TPM_NUM_FAMILY_TABLE_ENTRY_MIN];
+//} TPM_FAMILY_TABLE;
+
+
+typedef struct tdTPM_DELEGATE_LABEL
+{
+ UINT8 label;
+} TPM_DELEGATE_LABEL;
+
+
+typedef UINT32 TPM_DELEGATE_TYPE;
+#define TPM_DEL_OWNER_BITS ((UINT32)0x00000001)
+#define TPM_DEL_KEY_BITS ((UINT32)0x00000002)
+
+typedef struct tdTPM_DELEGATIONS
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DELEGATE_TYPE delegateType;
+ UINT32 per1;
+ UINT32 per2;
+} TPM_DELEGATIONS;
+
+typedef struct tdTPM_DELEGATE_PUBLIC
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DELEGATE_LABEL label;
+ TPM_PCR_INFO_SHORT pcrInfo;
+ TPM_DELEGATIONS permissions;
+ TPM_FAMILY_ID familyID;
+ TPM_FAMILY_VERIFICATION verificationCount;
+} TPM_DELEGATE_PUBLIC;
+
+typedef struct tdTPM_DELEGATE_TABLE_ROW
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DELEGATE_PUBLIC pub;
+ TPM_SECRET authValue;
+} TPM_DELEGATE_TABLE_ROW;
+
+
+#define TPM_NUM_DELEGATE_TABLE_ENTRY_MIN 2
+//typedef struct tdTPM_DELEGATE_TABLE
+//{
+// TPM_DELEGATE_TABLE_ROW delRow[TPM_NUM_DELEGATE_TABLE_ENTRY_MIN];
+//} TPM_DELEGATE_TABLE;
+
+typedef struct tdTPM_DELEGATE_SENSITIVE
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_SECRET authValue;
+} TPM_DELEGATE_SENSITIVE;
+
+typedef struct tdTPM_DELEGATE_OWNER_BLOB
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DELEGATE_PUBLIC pub;
+ TPM_DIGEST integrityDigest;
+ UINT32 additionalSize;
+ UINT8 *additionalArea;
+ UINT32 sensitiveSize;
+ UINT8 *sensitiveArea;
+} TPM_DELEGATE_OWNER_BLOB;
+
+typedef struct tdTPM_DELEGATE_KEY_BLOB
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DELEGATE_PUBLIC pub;
+ TPM_DIGEST integrityDigest;
+ TPM_DIGEST pubKeyDigest;
+ UINT32 additionalSize;
+ UINT8 *additionalArea;
+ UINT32 sensitiveSize;
+ UINT8 *sensitiveArea;
+} TPM_DELEGATE_KEY_BLOB;
+
+//
+// Part 2, section 21.1: TPM_CAPABILITY_AREA for GetCapability
+//
+#define TPM_CAP_ORD ((TPM_CAPABILITY_AREA) 0x00000001)
+#define TPM_CAP_ALG ((TPM_CAPABILITY_AREA) 0x00000002)
+#define TPM_CAP_PID ((TPM_CAPABILITY_AREA) 0x00000003)
+#define TPM_CAP_FLAG ((TPM_CAPABILITY_AREA) 0x00000004)
+#define TPM_CAP_PROPERTY ((TPM_CAPABILITY_AREA) 0x00000005)
+#define TPM_CAP_VERSION ((TPM_CAPABILITY_AREA) 0x00000006)
+#define TPM_CAP_KEY_HANDLE ((TPM_CAPABILITY_AREA) 0x00000007)
+#define TPM_CAP_CHECK_LOADED ((TPM_CAPABILITY_AREA) 0x00000008)
+#define TPM_CAP_SYM_MODE ((TPM_CAPABILITY_AREA) 0x00000009)
+#define TPM_CAP_KEY_STATUS ((TPM_CAPABILITY_AREA) 0x0000000C)
+#define TPM_CAP_NV_LIST ((TPM_CAPABILITY_AREA) 0x0000000D)
+#define TPM_CAP_MFR ((TPM_CAPABILITY_AREA) 0x00000010)
+#define TPM_CAP_NV_INDEX ((TPM_CAPABILITY_AREA) 0x00000011)
+#define TPM_CAP_TRANS_ALG ((TPM_CAPABILITY_AREA) 0x00000012)
+#define TPM_CAP_HANDLE ((TPM_CAPABILITY_AREA) 0x00000014)
+#define TPM_CAP_TRANS_ES ((TPM_CAPABILITY_AREA) 0x00000015)
+#define TPM_CAP_AUTH_ENCRYPT ((TPM_CAPABILITY_AREA) 0x00000017)
+#define TPM_CAP_SELECT_SIZE ((TPM_CAPABILITY_AREA) 0x00000018)
+#define TPM_CAP_VERSION_VAL ((TPM_CAPABILITY_AREA) 0x0000001A)
+
+#define TPM_CAP_FLAG_PERMANENT ((TPM_CAPABILITY_AREA) 0x00000108)
+#define TPM_CAP_FLAG_VOLATILE ((TPM_CAPABILITY_AREA) 0x00000109)
+
+//
+// Part 2, section 21.2: CAP_PROPERTY Subcap values for GetCapability
+//
+#define TPM_CAP_PROP_PCR ((TPM_CAPABILITY_AREA) 0x00000101)
+#define TPM_CAP_PROP_DIR ((TPM_CAPABILITY_AREA) 0x00000102)
+#define TPM_CAP_PROP_MANUFACTURER ((TPM_CAPABILITY_AREA) 0x00000103)
+#define TPM_CAP_PROP_KEYS ((TPM_CAPABILITY_AREA) 0x00000104)
+#define TPM_CAP_PROP_MIN_COUNTER ((TPM_CAPABILITY_AREA) 0x00000107)
+#define TPM_CAP_PROP_AUTHSESS ((TPM_CAPABILITY_AREA) 0x0000010A)
+#define TPM_CAP_PROP_TRANSESS ((TPM_CAPABILITY_AREA) 0x0000010B)
+#define TPM_CAP_PROP_COUNTERS ((TPM_CAPABILITY_AREA) 0x0000010C)
+#define TPM_CAP_PROP_MAX_AUTHSESS ((TPM_CAPABILITY_AREA) 0x0000010D)
+#define TPM_CAP_PROP_MAX_TRANSESS ((TPM_CAPABILITY_AREA) 0x0000010E)
+#define TPM_CAP_PROP_MAX_COUNTERS ((TPM_CAPABILITY_AREA) 0x0000010F)
+#define TPM_CAP_PROP_MAX_KEYS ((TPM_CAPABILITY_AREA) 0x00000110)
+#define TPM_CAP_PROP_OWNER ((TPM_CAPABILITY_AREA) 0x00000111)
+#define TPM_CAP_PROP_CONTEXT ((TPM_CAPABILITY_AREA) 0x00000112)
+#define TPM_CAP_PROP_MAX_CONTEXT ((TPM_CAPABILITY_AREA) 0x00000113)
+#define TPM_CAP_PROP_FAMILYROWS ((TPM_CAPABILITY_AREA) 0x00000114)
+#define TPM_CAP_PROP_TIS_TIMEOUT ((TPM_CAPABILITY_AREA) 0x00000115)
+#define TPM_CAP_PROP_STARTUP_EFFECT ((TPM_CAPABILITY_AREA) 0x00000116)
+#define TPM_CAP_PROP_DELEGATE_ROW ((TPM_CAPABILITY_AREA) 0x00000117)
+#define TPM_CAP_PROP_DAA_MAX ((TPM_CAPABILITY_AREA) 0x00000119)
+#define CAP_PROP_SESSION_DAA ((TPM_CAPABILITY_AREA) 0x0000011A)
+#define TPM_CAP_PROP_CONTEXT_DIST ((TPM_CAPABILITY_AREA) 0x0000011B)
+#define TPM_CAP_PROP_DAA_INTERRUPT ((TPM_CAPABILITY_AREA) 0x0000011C)
+#define TPM_CAP_PROP_SESSIONS ((TPM_CAPABILITY_AREA) 0x0000011D)
+#define TPM_CAP_PROP_MAX_SESSIONS ((TPM_CAPABILITY_AREA) 0x0000011E)
+#define TPM_CAP_PROP_CMK_RESTRICTION ((TPM_CAPABILITY_AREA) 0x0000011F)
+#define TPM_CAP_PROP_DURATION ((TPM_CAPABILITY_AREA) 0x00000120)
+#define TPM_CAP_PROP_ACTIVE_COUNTER ((TPM_CAPABILITY_AREA) 0x00000122)
+#define TPM_CAP_PROP_MAX_NV_AVAILABLE ((TPM_CAPABILITY_AREA) 0x00000123)
+#define TPM_CAP_PROP_INPUT_BUFFER ((TPM_CAPABILITY_AREA) 0x00000124)
+
+//
+// Part 2, section 21.6: TPM_CAP_VERSION_INFO
+// [size_is(vendorSpecificSize)] BYTE* vendorSpecific;
+//
+typedef struct tdTPM_CAP_VERSION_INFO
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_VERSION version;
+ UINT16 specLevel;
+ UINT8 errataRev;
+ UINT8 tpmVendorID[4];
+ UINT16 vendorSpecificSize;
+ UINT8 *vendorSpecific;
+} TPM_CAP_VERSION_INFO;
+
+//
+// Part 2, section 22: DAA Structures
+//
+
+#define TPM_DAA_SIZE_r0 (43)
+#define TPM_DAA_SIZE_r1 (43)
+#define TPM_DAA_SIZE_r2 (128)
+#define TPM_DAA_SIZE_r3 (168)
+#define TPM_DAA_SIZE_r4 (219)
+#define TPM_DAA_SIZE_NT (20)
+#define TPM_DAA_SIZE_v0 (128)
+#define TPM_DAA_SIZE_v1 (192)
+#define TPM_DAA_SIZE_NE (256)
+#define TPM_DAA_SIZE_w (256)
+#define TPM_DAA_SIZE_issuerModulus (256)
+#define TPM_DAA_power0 (104)
+#define TPM_DAA_power1 (1024)
+
+typedef struct tdTPM_DAA_ISSUER
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DIGEST DAA_digest_R0;
+ TPM_DIGEST DAA_digest_R1;
+ TPM_DIGEST DAA_digest_S0;
+ TPM_DIGEST DAA_digest_S1;
+ TPM_DIGEST DAA_digest_n;
+ TPM_DIGEST DAA_digest_gamma;
+ UINT8 DAA_generic_q[26];
+} TPM_DAA_ISSUER;
+
+
+typedef struct tdTPM_DAA_TPM
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DIGEST DAA_digestIssuer;
+ TPM_DIGEST DAA_digest_v0;
+ TPM_DIGEST DAA_digest_v1;
+ TPM_DIGEST DAA_rekey;
+ UINT32 DAA_count;
+} TPM_DAA_TPM;
+
+typedef struct tdTPM_DAA_CONTEXT
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_DIGEST DAA_digestContext;
+ TPM_DIGEST DAA_digest;
+ TPM_DAA_CONTEXT_SEED DAA_contextSeed;
+ UINT8 DAA_scratch[256];
+ UINT8 DAA_stage;
+} TPM_DAA_CONTEXT;
+
+typedef struct tdTPM_DAA_JOINDATA
+{
+ UINT8 DAA_join_u0[128];
+ UINT8 DAA_join_u1[138];
+ TPM_DIGEST DAA_digest_n0;
+} TPM_DAA_JOINDATA;
+
+typedef struct tdTPM_DAA_BLOB
+{
+ TPM_STRUCTURE_TAG tag;
+ TPM_RESOURCE_TYPE resourceType;
+ UINT8 label[16];
+ TPM_DIGEST blobIntegrity;
+ UINT32 additionalSize;
+ UINT8 *additionalData;
+ UINT32 sensitiveSize;
+ UINT8 *sensitiveData;
+} TPM_DAA_BLOB;
+
+typedef struct tdTPM_DAA_SENSITIVE
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT32 internalSize;
+ UINT8 *internalData;
+} TPM_DAA_SENSITIVE;
+
+
+//
+// Part 2, section 23: Redirection
+//
+
+// This section of the TPM spec defines exactly one value but does not
+// give it a name. The definition of TPM_SetRedirection in Part3
+// refers to exactly one name but does not give its value. We join
+// them here.
+#define TPM_REDIR_GPIO (0x00000001)
+
+//
+// TPM Command & Response Headers
+//
+typedef struct tdTPM_RQU_COMMAND_HDR
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT32 paramSize;
+ TPM_COMMAND_CODE ordinal;
+} TPM_RQU_COMMAND_HDR;
+
+typedef struct tdTPM_RSP_COMMAND_HDR
+{
+ TPM_STRUCTURE_TAG tag;
+ UINT32 paramSize;
+ TPM_RESULT returnCode;
+} TPM_RSP_COMMAND_HDR;
+
+#pragma pack (pop)
+
+#endif // _TPM12_H_
diff --git a/Core/EM/TCG2/TisLib/TcmPc.h b/Core/EM/TCG2/TisLib/TcmPc.h
new file mode 100644
index 0000000..9431fa3
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TcmPc.h
@@ -0,0 +1,153 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcmPc.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcmPc.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 2 3/29/11 12:27p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TcmPc.h
+//
+// Description:
+// Header file for Tcm structures
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#ifndef _TCMPC_H_
+#define _TCMPC_H_
+#include "TcgEfi12.h"
+
+
+#pragma pack (push)
+#pragma pack (1)
+
+
+
+typedef struct tdTCM_PCR_EVENT {
+ UINT32 PCRIndex; // PCRIndex event extended to
+ UINT32 EventType; // TCG EFI event type
+ TCM_DIGEST Digest; // Value extended into PCRIndex
+ UINT32 EventSize; // Size of the event data
+ UINT8 Event[1]; // The event data
+} TCM_PCR_EVENT;
+
+
+struct _EFI_TCM_EV_S_CRTM_VERSION {
+ EFI_GUID VersionGuid;
+};
+
+
+struct _EFI_TCM_EV_POST_CODE {
+ EFI_PHYSICAL_ADDRESS PostCodeAddress;
+ UINT64 PostCodeLength;
+};
+
+
+struct _EFI_TCM_EV_TAG_OPTION_ROM_EXECUTE
+{
+ UINT16 Reserved;
+ UINT16 PFA;
+ TCM_DIGEST Hash;
+};
+
+
+struct _EFI_TCM_EV_CPU_MICROCODE
+{
+ EFI_PHYSICAL_ADDRESS MicrocodeEntrypoint;
+};
+
+
+union _EFI_TCM_EV_TAG_EVENT_DATA
+{
+ struct _EFI_TCM_EV_TAG_OPTION_ROM_EXECUTE
+ OptionRomExecute;
+};
+
+
+struct _EFI_TCM_EV_TAG
+{
+ UINT32 EventID;
+ UINT32 EventSize;
+ union _EFI_TCM_EV_TAG_EVENT_DATA EventData;
+};
+
+
+typedef struct _EFI_TCM_PCR_EVENT_HEADER
+{
+ TPM_PCRINDEX PCRIndex;
+ UINT32 EventType;
+ TCM_DIGEST Digest;
+ UINT32 EventDataSize;
+} EFI_TCM_PCR_EVENT_HEADER;
+
+
+typedef union _EFI_TCM_PCR_EVENT_DATA
+{
+ struct _EFI_TCM_EV_S_CRTM_VERSION SCrtmVersion;
+ struct _EFI_TCM_EV_POST_CODE PostCode;
+ struct _EFI_TCM_EV_TAG Tagged;
+ struct _EFI_TCM_EV_CPU_MICROCODE Mcu;
+} EFI_TCM_PCR_EVENT_DATA;
+
+
+
+typedef struct _EFI_TCM_PCR_EVENT
+{
+ EFI_TCM_PCR_EVENT_HEADER Header;
+ EFI_TCM_PCR_EVENT_DATA Event;
+} EFI_TCM_PCR_EVENT;
+
+#pragma pack (pop)
+
+#endif // _TPMPC_H_
diff --git a/Core/EM/TCG2/TisLib/TisLib.cif b/Core/EM/TCG2/TisLib/TisLib.cif
new file mode 100644
index 0000000..fcafbfb
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TisLib.cif
@@ -0,0 +1,23 @@
+<component>
+ name = "TisLib"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\TisLib"
+ RefName = "TisLib"
+[files]
+"TisLib.mak"
+"TcgTpm12.h"
+"TpmLib.h"
+"TcgCommon.h"
+"ZTEICTcmOrdinals.h"
+"TpmLib.c"
+"TcgCommon.c"
+"TisLib.sdl"
+"sha.h"
+"INTTcgAcpi.h"
+"TcgPc.h"
+"TcmPc.h"
+"TcgEfiTpm.h"
+"TcgEFI12.h"
+[parts]
+"AmiTcmlib"
+<endComponent>
diff --git a/Core/EM/TCG2/TisLib/TisLib.mak b/Core/EM/TCG2/TisLib/TisLib.mak
new file mode 100644
index 0000000..1e79a4f
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TisLib.mak
@@ -0,0 +1,116 @@
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
+#**********************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TisLib.mak 1 4/21/14 2:14p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:14p $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TisLib.mak $
+#
+# 1 4/21/14 2:14p Fredericko
+#
+# 1 10/08/13 11:58a Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 2 10/03/13 12:31p Fredericko
+#
+# 1 7/10/13 5:50p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+# [Files] TisLib.cif
+# TisLib.mak
+# TcgTpm12.h
+# TpmLib.h
+# TcgCommon.h
+# ZTEICTcmOrdinals.h
+# TpmLib.c
+# TcgCommon.c
+# TisLib.sdl
+# sha1.h
+# INTTcgAcpi.h
+# TcgPc.h
+# TcmPc.h
+# TcgEfiTpm.h
+# TcgEFI12.h
+#
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: Tpm12lib.mak
+#
+# Description: Make file for the tcglib component
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+Tpm12_lib : $(BUILD_DIR)\TisLib.mak make_TisLib_lib make_TisLib_libPei
+$(BUILD_DIR)\TisLib.lib: Tpm12_lib
+$(BUILD_DIR)\IA32\TisLib.lib: Tpm12_lib
+
+tcg_lib_lite: $(BUILD_DIR)\TisLib.mak tcg_lib_liteBin
+$(tcgLibLite): tcg_lib_lite
+
+$(BUILD_DIR)\TisLib.mak : $(TPM12_DIR)\TisLib.cif $(TPM12_DIR)\TisLib.mak $(BUILD_RULES)
+ $(CIF2MAK) $(TPM12_DIR)\TisLib.cif $(CIF2MAK_DEFAULTS)
+
+TCG12LIB_CFLAGS=$(CFLAGS)\
+ /I$(TPM12_DIR)\
+ /I$(TCG_DIR)\
+
+TCG_LIB_LITE_OBJS = \
+$(BUILD_DIR)\$(TPM12_DIR)\TpmLib.obj
+
+tcg_lib_liteBin: $(BUILD_DIR)\AmiTcmlib.lib
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TisLib.mak all\
+ "CFLAGS=$(TCG12LIB_CFLAGS) "\
+ "OBJECTS=$(TCG_LIB_LITE_OBJS)"\
+ TYPE=LIBRARY \
+ LIBRARY_NAME=$(tcgLibLite)
+
+!IF "$(PROCESSOR)"=="x64"
+make_TisLib_lib: $(BUILD_DIR)\AmiTcmlib.lib $(SHALIB)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TisLib.mak all\
+ "CFLAGS=$(TCG12LIB_CFLAGS) "\
+ TYPE=LIBRARY
+
+make_TisLib_libPei: $(BUILD_DIR)\AmiTcmlib.lib $(SHALIBPEI)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS) BUILD_DIR=$(BUILD_DIR)\IA32\
+ /f $(BUILD_DIR)\TisLib.mak all\
+ "CFLAGS=$(TCG12LIB_CFLAGS) "\
+ TYPE=PEI_LIBRARY
+!ELSE
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TisLib.mak all\
+ "CFLAGS=$(TCG12LIB_CFLAGS) "\
+ TYPE=PEI_LIBRARY
+!ENDIF
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
diff --git a/Core/EM/TCG2/TisLib/TisLib.sdl b/Core/EM/TCG2/TisLib/TisLib.sdl
new file mode 100644
index 0000000..95ee12d
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TisLib.sdl
@@ -0,0 +1,46 @@
+TOKEN
+ Name = "TPM12_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable TCG support in Project"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Master = Yes
+ Token = "TCG2Support" "=" "1"
+End
+
+TOKEN
+ Name = "TPM_DRIVER_WAIT"
+ Value = "005h"
+ Help = "Delay count for TPM wait loop. Default is 50us. Please dont change to less than 2 (4us)."
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+TOKEN
+ Name = "DELAY_AMOUNT"
+ Value = "010"
+ Help = "Delay amount for TPM wait loop. Default is 5us. Please dont change to less than 2 (2us)."
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+PATH
+ Name = "TPM12_DIR"
+ Help = "Tcg Directory"
+End
+
+MODULE
+ Help = "Includes TCG.mak to Project"
+ File = "TisLib.mak"
+End
+
+TOKEN
+ Name = "tcgLibLite"
+ Value = "$(BUILD_DIR)\tcgLibLite.lib"
+ TokenType = Expression
+ TargetMAK = Yes
+End \ No newline at end of file
diff --git a/Core/EM/TCG2/TisLib/TpmLib.c b/Core/EM/TCG2/TisLib/TpmLib.c
new file mode 100644
index 0000000..66dd24a
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TpmLib.c
@@ -0,0 +1,614 @@
+/*++
+
+Copyright (c) 2005 Intel Corporation. All rights reserved
+This software and associated documentation (if any) is furnished
+under a license and may only be used or copied in accordance
+with the terms of the license. Except as permitted by such
+license, no part of this software or documentation may be
+reproduced, stored in a retrieval system, or transmitted in any
+form or by any means without the express written consent of
+Intel Corporation.
+
+
+Module Name:
+
+ TpmLib.h
+
+Abstract:
+
+ Common code of TPM driver in both PEI and DXE
+--*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TpmLib.c 1 4/21/14 2:14p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:14p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TpmLib.c $
+//
+// 1 4/21/14 2:14p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 2 10/03/13 12:33p Fredericko
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 23 9/08/11 4:46p Fredericko
+// [TAG] EIPEIP0000
+// [Category] Improvement
+// [Description] Added ability to modify Delay Amount for TPM driver
+// [Files] Tcg.sdl
+// Tpmlib.c
+//
+// 22 8/26/11 12:31p Fredericko
+// [TAG] EIP64300
+// [Category] Improvement
+// [Description] Allow variations for TPM driver wait times.
+// [Files] Tpmlib.c
+// Tcg.sd
+//
+// 21 7/07/10 12:09p Fredericko
+// Make Wait variable a #define.
+//
+// 20 5/19/10 4:50p Fredericko
+// Included File Header
+//
+// 19 5/18/10 5:39p Fredericko
+// Code Beautification and Enhancement
+//
+// 18 5/18/10 11:32a Fredericko
+// Header modification for AMI code standard.
+//
+// 17 5/04/10 3:36p Fredericko
+// Source Enhancement. EIP 22208
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TpmLib.c
+//
+// Description:
+// Contains low level TCG functions
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Efi.h>
+#include "TpmLib.h"
+#include "AmiLib.h"
+#include <token.h>
+
+extern EFI_STATUS CountTime ( IN UINTN DelayTime, IN UINT16 BaseAddr); // only needs to be 16 bit for I/O address)
+#define Wait TPM_DRIVER_WAIT
+#define ACCESS_WAITCOUNT (750 * 1000 / 100) // 750MS (750 * 10000 /1000)
+#define ACCESS_WAITCOUNTB ( 3 * 1000000/100) // 3 seconds delay
+
+#define TIS_TIMEOUT_A ACCESS_WAITCOUNT
+#define TIS_TIMEOUT_B ACCESS_WAITCOUNTB
+#define TIS_TIMEOUT_C ACCESS_WAITCOUNT
+#define TIS_TIMEOUT_D ACCESS_WAITCOUNT
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: FixedDelay
+//
+// Description: This routine delays for specified number of micro seconds
+//
+// Input: IN UINT32 dCount Amount of delay (count in 20microsec)
+//
+// Output: NONE
+//
+// Modified:
+//
+// Referrals: Div64, CountTime
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+
+void
+__stdcall
+FixedDelay(UINT32 dCount)
+{
+ UINTN TickPeriod = 0x03;
+ UINTN Remainder = 0x1;
+ UINTN MicroSDelay = DELAY_AMOUNT;
+ UINT32 Data32, PrevData;
+ UINTN i=0;
+ UINT32 Counter = 0x00;
+
+ Counter = (UINT32)Div64((MicroSDelay * 10), TickPeriod, &Remainder);
+
+ if(Remainder != 0) {
+ Counter++;
+ }
+ while(dCount) {
+ if (Counter != 0) {
+
+ PrevData = IoRead32(PM_BASE_ADDRESS + 8);
+ for (i=0; i < Counter; ) {
+ Data32 = IoRead32(PM_BASE_ADDRESS + 8);
+ if (Data32 < PrevData) { // Reset if there is a overlap
+ PrevData=Data32;
+ continue;
+ }
+ i += (Data32 - PrevData);
+ PrevData = Data32;
+ }
+ }
+ dCount--;
+ }
+}
+
+
+
+static
+UINT8
+__stdcall
+CheckAccessBit (
+ IN volatile UINT8 *Sts,
+ IN UINT8 Bit,
+ IN UINT32 Timeout
+ )
+/*++
+Routine Description:
+ Function to check bits in TPM access register
+Arguments:
+ *Sts - A Pointer to Status register
+ Bit - Bit position
+ Timeout - Timeout amount to wait till the specified bit
+Returns:
+ EFI_Status
+--*/
+{
+ UINT32 AccessCount = Timeout;
+
+ if(!(*Sts & TPM_STS_VALID))
+ return 0;
+
+ do {
+
+ FixedDelay((UINT32)Wait);
+ if((*Sts & Bit)){ return *Sts & Bit; }
+ AccessCount--;
+ } while (AccessCount);
+
+ return 0;
+}
+
+
+
+static
+UINT8
+__stdcall
+CheckStsBit (
+ IN volatile UINT8 *Sts,
+ IN UINT8 Bit
+ )
+/*++
+Routine Description:
+ Function to check status a specific TPM status bit
+Arguments:
+ *Sts - A Pointer to Status register
+ Bit - Bit position
+Returns:
+ EFI_Status
+--*/
+{
+ while (!(*Sts & TPM_STS_VALID));
+ return *Sts & Bit;
+}
+
+
+
+
+static
+UINT16
+__stdcall
+ReadBurstCount (
+ IN TPM_1_2_REGISTERS_PTR TpmReg
+)
+/*++
+Routine Description:
+ Gets the number of bytes (burstCount) that the TPM can return
+ on reads or accept on writes without inserting LPC long wait
+ states on the LPC bus.
+ burstCount is TPM_STS_x register bits 8..23
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+Returns:
+ 0 - Any Errors
+ burstCount - TPM_STS_x.burstCount
+--*/
+{
+ UINT16 burstCount;
+ UINT64 Deadline = TIS_TIMEOUT_D;
+
+ burstCount = 0;
+
+ do {
+ //
+ // burstCount is little-endian bit ordering
+ //
+ FixedDelay((UINT32)Wait);
+ Deadline--;
+ burstCount = TpmReg->BurstCount;
+ }while (!burstCount && (Deadline > 0));
+
+ return burstCount;
+}
+
+
+
+EFI_STATUS
+__stdcall
+TisRequestLocality (
+ IN TPM_1_2_REGISTERS_PTR TpmReg
+ )
+/*++
+Routine Description:
+ Requests TPM locality 0
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+Returns:
+ EFI_Status
+--*/
+{
+ if ((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)==TPM_ACC_ACTIVE_LOCALITY){
+ return EFI_SUCCESS;//EFI_ALREADY_STARTED;
+ }
+ TpmReg->Access = TPM_ACC_REQUEST_USE;
+ if (CheckAccessBit(&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY, (UINT32)TIS_TIMEOUT_B)) {
+ return EFI_SUCCESS;
+ } else {
+ return EFI_NOT_READY;
+ }
+}
+
+
+
+#pragma optimize("",off)
+EFI_STATUS
+__stdcall
+TisReleaseLocality (
+ IN TPM_1_2_REGISTERS_PTR TpmReg
+ )
+/*++
+Routine Description:
+ Release TPM locality 0
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+Returns:
+ EFI_Status
+--*/
+{
+ UINT32 AccessCount=ACCESS_WAITCOUNT;
+ if (!CheckStsBit (&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY)) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ TpmReg->Access = TPM_ACC_ACTIVE_LOCALITY;
+ if (CheckStsBit(&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY)) {
+ do{/*give locality time to be released*/
+ FixedDelay((UINT32)Wait);
+ AccessCount--;
+ }while(((CheckStsBit(&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY)) && AccessCount));
+ if(CheckStsBit(&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY)){return EFI_DEVICE_ERROR;}
+ else{return EFI_SUCCESS;}
+ } else {
+ return EFI_SUCCESS;
+ }
+}
+#pragma optimize("",on)
+
+
+
+
+EFI_STATUS
+__stdcall
+TisPrepareSendCommand (
+ IN TPM_1_2_REGISTERS_PTR TpmReg
+ )
+/*++
+Routine Description:
+ Helper function to prepare to send a TPM command
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+Returns:
+ EFI_Status
+--*/
+{
+
+ if((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)!=TPM_ACC_ACTIVE_LOCALITY){
+ return EFI_NOT_STARTED;
+ }
+
+ do {
+ TpmReg->Sts = TPM_STS_READY;
+ } while (!(TpmReg->Sts & TPM_STS_READY));
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+__stdcall
+TisSendCommand (
+ IN TPM_1_2_REGISTERS_PTR TpmReg,
+ IN const VOID *CmdStream,
+ IN UINTN Size,
+ IN BOOLEAN Last
+ )
+/*++
+Routine Description:
+ Function to send TPM command
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+ *CmdStream - A Pointer to the command stream to be sent to TPM Fifo
+ Size - Size in bytes of the command stream
+ Last - Boolean to signify the last byte?
+Returns:
+ EFI_Status
+--*/
+{
+ UINT8 *Ptr;
+ UINT16 burstCount;
+
+ if (Size == 0) {
+ return Last ? EFI_INVALID_PARAMETER : EFI_SUCCESS;
+ }
+
+ if ((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)!=TPM_ACC_ACTIVE_LOCALITY) {
+ return EFI_ABORTED;
+ }
+
+ Ptr = (UINT8*)CmdStream;
+
+ if (Last) {
+ Size--;
+ }
+
+ while (Size > 0) {
+ burstCount = ReadBurstCount(TpmReg);
+ if (burstCount == 0) {
+ // Cannot get the correct burstCount value
+ return EFI_TIMEOUT;
+ }
+
+ for (; burstCount > 0 && Size > 0; burstCount--) {
+ *(UINT8*)&TpmReg->DataFifo = *Ptr;
+ Ptr++;
+ Size--;
+ }
+ }
+
+ if (Last) {
+ if (!CheckStsBit (&TpmReg->Sts, TPM_STS_EXPECT)) {
+ return EFI_ABORTED;
+ }
+
+ *(UINT8*)&TpmReg->DataFifo = *Ptr;
+
+ if (CheckStsBit (&TpmReg->Sts, TPM_STS_EXPECT)) {
+ return EFI_ABORTED;
+ }
+
+ TpmReg->Sts = TPM_STS_GO;
+
+ }
+ return EFI_SUCCESS;
+}
+
+
+
+
+EFI_STATUS
+__stdcall
+TisWaitForResponse (
+ IN TPM_1_2_REGISTERS_PTR TpmReg
+ )
+/*++
+Routine Description:
+ Waits till TPM result is available
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+Returns:
+ EFI_Status
+--*/
+{
+ if((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)!=TPM_ACC_ACTIVE_LOCALITY){
+ return EFI_NOT_STARTED;
+ }
+
+ while (!CheckStsBit (&TpmReg->Sts, TPM_STS_DATA_AVAILABLE));
+ return EFI_SUCCESS;
+}
+
+
+
+
+EFI_STATUS
+__stdcall
+TisReceiveResponse (
+ IN TPM_1_2_REGISTERS_PTR TpmReg,
+ OUT VOID *Buffer,
+ OUT UINTN *Size
+ )
+/*++
+Routine Description:
+ Function to recieve TPM command results
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+ *Buffer - A Pointer to buffer for recieving result data
+ Size - buffer size
+Returns:
+ EFI_Status
+--*/
+{
+ UINT8 *Ptr, *BufEnd;
+ UINT16 burstCount;
+
+ if((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)!=TPM_ACC_ACTIVE_LOCALITY) {
+ return EFI_ABORTED;
+ }
+
+ Ptr = (UINT8*)Buffer;
+ BufEnd = Ptr + *Size;
+ while (Ptr < BufEnd &&
+ CheckStsBit (&TpmReg->Sts, TPM_STS_DATA_AVAILABLE)) {
+
+ burstCount = ReadBurstCount(TpmReg);
+ if (burstCount == 0) {
+ return EFI_TIMEOUT;
+ }
+ while(burstCount && Ptr < BufEnd && CheckStsBit (&TpmReg->Sts, TPM_STS_DATA_AVAILABLE )){
+ *Ptr++ = *(UINT8*)&TpmReg->DataFifo;
+ burstCount--; }
+ }
+
+ *Size -= BufEnd - Ptr;
+ if (CheckStsBit (&TpmReg->Sts, TPM_STS_DATA_AVAILABLE)) {
+ return EFI_BUFFER_TOO_SMALL;
+ } else {
+ return EFI_SUCCESS;
+ }
+}
+
+
+
+VOID
+__stdcall
+TisResendResponse (
+ IN TPM_1_2_REGISTERS_PTR TpmReg
+ )
+/*++
+Routine Description:
+ Sets Bit to resend TPM command
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+Returns:
+ EFI_Status
+--*/
+{
+ TpmReg->Sts = TPM_STS_RESPONSE_RETRY;
+}
+
+EFI_STATUS
+__stdcall
+IsTpmPresent (
+ IN TPM_1_2_REGISTERS_PTR TpmReg
+ )
+{
+ if (TpmReg->Access == 0xff) {
+ return EFI_NOT_FOUND;
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+
+
+EFI_STATUS
+__stdcall
+TpmLibPassThrough (
+ IN TPM_1_2_REGISTERS_PTR TpmReg,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers
+ )
+/*++
+Routine Description:
+ Higher level function to send a recieve commands to the TPM
+Arguments:
+ TpmReg - A Pointer to the TPM Register Space
+ NoInputBuffers - Number count of Input buffers
+ *InputBuffers - Pointer to InputBuffers[0]
+ NoOutputBuffers - Number count of Output buffers
+ *OutputBuffers - Pointer to OutputBuffers[0]
+Returns:
+ EFI_Status
+--*/
+{
+ EFI_STATUS Status;
+ UINTN i;
+
+ if (NoInputBuffers == 0 || InputBuffers->Size < sizeof (TPM_1_2_CMD_HEADER)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ do {
+ NoInputBuffers--;
+ } while (InputBuffers[NoInputBuffers].Size == 0 && NoInputBuffers > 0);
+
+ if (InputBuffers[NoInputBuffers].Size == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = TisPrepareSendCommand (TpmReg);
+
+ for (i = 0; !EFI_ERROR (Status) && i < NoInputBuffers; i++) {
+ Status = TisSendCommand (
+ TpmReg,
+ InputBuffers[i].Buffer,
+ InputBuffers[i].Size,
+ FALSE
+ );
+ }
+
+ if (!EFI_ERROR (Status)) {
+ Status = TisSendCommand (
+ TpmReg,
+ InputBuffers[i].Buffer,
+ InputBuffers[i].Size,
+ TRUE
+ );
+ }
+
+ if (!EFI_ERROR (Status)) {
+ Status = TisWaitForResponse (TpmReg);
+ }
+
+ if (EFI_ERROR (Status)) {
+ goto Exit;
+ }
+
+ Status = EFI_BUFFER_TOO_SMALL;
+ for (i = 0; Status == EFI_BUFFER_TOO_SMALL && i < NoOutputBuffers; i++) {
+ Status = TisReceiveResponse (
+ TpmReg,
+ OutputBuffers[i].Buffer,
+ &OutputBuffers[i].Size
+ );
+ }
+
+Exit:
+ TisCompleteCommand (TpmReg);
+ return Status;
+}
diff --git a/Core/EM/TCG2/TisLib/TpmLib.h b/Core/EM/TCG2/TisLib/TpmLib.h
new file mode 100644
index 0000000..1e98660
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/TpmLib.h
@@ -0,0 +1,136 @@
+/*++
+
+ Copyright (c) 2005 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ TpmLib.h
+
+ Abstract:
+
+ Header file for tpm device drivers
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TpmLib.h 1 4/21/14 2:14p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:14p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TpmLib.h $
+//
+// 1 4/21/14 2:14p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 3 5/19/10 5:11p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TpmLib.c
+//
+// Description:
+// Header file for TpmLib.c
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+#ifndef _TPMLIB_H_
+#define _TPMLIB_H_
+
+#include "TcgPc.h"
+
+#define TisCompleteCommand TisPrepareSendCommand
+
+extern
+EFI_STATUS
+__stdcall TisRequestLocality (
+ IN TPM_1_2_REGISTERS_PTR TpmReg );
+
+extern
+EFI_STATUS
+__stdcall TisReleaseLocality (
+ IN TPM_1_2_REGISTERS_PTR TpmReg );
+
+extern
+EFI_STATUS
+__stdcall TisPrepareSendCommand (
+ IN TPM_1_2_REGISTERS_PTR TpmReg );
+
+extern
+EFI_STATUS
+__stdcall TisSendCommand (
+ IN TPM_1_2_REGISTERS_PTR TpmReg,
+ IN const VOID *CmdStream,
+ IN UINTN Size,
+ IN BOOLEAN Last );
+
+extern
+EFI_STATUS
+__stdcall TisWaitForResponse (
+ IN TPM_1_2_REGISTERS_PTR TpmReg );
+
+extern
+EFI_STATUS
+__stdcall TisReceiveResponse (
+ IN TPM_1_2_REGISTERS_PTR TpmReg,
+ OUT VOID *Buffer,
+ OUT UINTN *Size );
+
+extern
+EFI_STATUS
+__stdcall IsTpmPresent (
+ IN TPM_1_2_REGISTERS_PTR TpmReg );
+
+extern
+EFI_STATUS
+__stdcall TpmLibPassThrough (
+ IN TPM_1_2_REGISTERS_PTR TpmReg,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers );
+
+extern
+EFI_STATUS
+__stdcall TpmLibStartup (
+ IN UINT16 StartupType );
+
+#endif
diff --git a/Core/EM/TCG2/TisLib/ZTEICTcmOrdinals.h b/Core/EM/TCG2/TisLib/ZTEICTcmOrdinals.h
new file mode 100644
index 0000000..edf35ea
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/ZTEICTcmOrdinals.h
@@ -0,0 +1,203 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/ZTEICTcmOrdinals.h 1 4/21/14 2:14p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:14p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/ZTEICTcmOrdinals.h $
+//
+// 1 4/21/14 2:14p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 7 3/29/11 12:26p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: ZTEICTcmOrdinals.h
+//
+// Description:
+// Header file for ZTEIC specific ordinals
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#define TCM_ORD_ActivateIdentity ((UINT32) 0x0000807A)
+#define TCM_ORD_AuthorizeMigrationKey ((UINT32) 0x0000802B)
+#define TCM_ORD_CertifyKey ((UINT32) 0x00008032)
+#define TCM_ORD_CertifyKey2 ((UINT32) 0x00008033)
+#define TCM_ORD_CertifySelfTest ((UINT32) 0x00008052)
+#define TCM_ORD_ChangeAuth ((UINT32) 0x0000800C)
+#define TCM_ORD_ChangeAuthAsymFinish ((UINT32) 0x0000800F)
+#define TCM_ORD_ChangeAuthAsymStart ((UINT32) 0x0000800E)
+#define TCM_ORD_ChangeAuthOwner ((UINT32) 0x00008010)
+#define TCM_ORD_CMK_ApproveMA ((UINT32) 0x0000801D)
+#define TCM_ORD_CMK_ConvertMigration ((UINT32) 0x00008024)
+#define TCM_ORD_CMK_CreateBlob ((UINT32) 0x0000801B)
+#define TCM_ORD_CMK_CreateKey ((UINT32) 0x00008013)
+#define TCM_ORD_CMK_CreateTicket ((UINT32) 0x00008012)
+#define TCM_ORD_CMK_SetRestrictions ((UINT32) 0x0000801C)
+#define TCM_ORD_ContinueSelfTest ((UINT32) 0x00008053)
+#define TCM_ORD_ConvertMigrationBlob ((UINT32) 0x0000802A)
+#define TCM_ORD_CreateCounter ((UINT32) 0x000080DC)
+#define TCM_ORD_CreateEndorsementKeyPair ((UINT32) 0x00008078)
+#define TCM_ORD_CreateMaintenanceArchive ((UINT32) 0x0000802C)
+#define TCM_ORD_CreateMigrationBlob ((UINT32) 0x00008028)
+#define TCM_ORD_CreateRevocableEK ((UINT32) 0x0000807F)
+#define TCM_ORD_CreateWrapKey ((UINT32) 0x0000801F)
+#define TCM_ORD_DAA_JOIN ((UINT32) 0x00008029)
+#define TCM_ORD_DAA_SIGN ((UINT32) 0x00008031)
+#define TCM_ORD_Delegate_CreateKeyDelegation ((UINT32) 0x000080D4)
+#define TCM_ORD_Delegate_CreateOwnerDelegation ((UINT32) 0x000080D5)
+#define TCM_ORD_Delegate_LoadOwnerDelegation ((UINT32) 0x000080D8)
+#define TCM_ORD_Delegate_Manage ((UINT32) 0x000080D2)
+#define TCM_ORD_Delegate_ReadTable ((UINT32) 0x000080DB)
+#define TCM_ORD_Delegate_UpdateVerification ((UINT32) 0x000080D1)
+#define TCM_ORD_Delegate_VerifyDelegation ((UINT32) 0x000080D6)
+#define TCM_ORD_DirRead ((UINT32) 0x0000801A)
+#define TCM_ORD_DirWriteAuth ((UINT32) 0x00008019)
+#define TCM_ORD_DisableForceClear ((UINT32) 0x0000805E)
+#define TCM_ORD_DisableOwnerClear ((UINT32) 0x0000805C)
+#define TCM_ORD_DisablePubekRead ((UINT32) 0x0000807E)
+#define TCM_ORD_DSAP ((UINT32) 0x00008011)
+#define TCM_ORD_EstablishTransport ((UINT32) 0x000080E6)
+#define TCM_ORD_EvictKey ((UINT32) 0x00008022)
+#define TCM_ORD_ExecuteTransport ((UINT32) 0x000080E7)
+#define TCM_ORD_Extend ((UINT32) 0x00008014)
+#define TCM_ORD_FieldUpgrade ((UINT32) 0x000080AA)
+#define TCM_ORD_FlushSpecific ((UINT32) 0x000080BA)
+#define TCM_ORD_ForceClear ((UINT32) 0x0000805D)
+#define TCM_ORD_GetAuditDigest ((UINT32) 0x00008085)
+#define TCM_ORD_GetAuditDigestSigned ((UINT32) 0x00008086)
+#define TCM_ORD_GetAuditEvent ((UINT32) 0x00008082)
+#define TCM_ORD_GetAuditEventSigned ((UINT32) 0x00008083)
+#define TCM_ORD_GetCapability ((UINT32) 0x00008065)
+#define TCM_ORD_GetCapabilityOwner ((UINT32) 0x00008066)
+#define TCM_ORD_GetCapabilitySigned ((UINT32) 0x00008064)
+#define TCM_ORD_GetOrdinalAuditStatus ((UINT32) 0x0000808C)
+#define TCM_ORD_GetPubKey ((UINT32) 0x00008021)
+#define TCM_ORD_GetRandom ((UINT32) 0x00008046)
+#define TCM_ORD_GetTestResult ((UINT32) 0x00008054)
+#define TCM_ORD_GetTicks ((UINT32) 0x000080F1)
+#define TCM_ORD_IncrementCounter ((UINT32) 0x000080DD)
+#define TCM_ORD_Init ((UINT32) 0x00008097)
+#define TCM_ORD_KeyControlOwner ((UINT32) 0x00008023)
+#define TCM_ORD_KillMaintenanceFeature ((UINT32) 0x0000802E)
+#define TCM_ORD_LoadAuthContext ((UINT32) 0x000080B7)
+#define TCM_ORD_LoadContext ((UINT32) 0x000080B9)
+#define TCM_ORD_LoadKey ((UINT32) 0x00008020)
+#define TCM_ORD_LoadKey2 ((UINT32) 0x00008041)
+#define TCM_ORD_LoadKeyContext ((UINT32) 0x000080B5)
+#define TCM_ORD_LoadMaintenanceArchive ((UINT32) 0x0000802D)
+#define TCM_ORD_LoadManuMaintPub ((UINT32) 0x0000802F)
+#define TCM_ORD_MakeIdentity ((UINT32) 0x00008079)
+#define TCM_ORD_MigrateKey ((UINT32) 0x00008025)
+#define TCM_ORD_NV_DefineSpace ((UINT32) 0x000080CC)
+#define TCM_ORD_NV_ReadValue ((UINT32) 0x000080CF)
+#define TCM_ORD_NV_ReadValueAuth ((UINT32) 0x000080D0)
+#define TCM_ORD_NV_WriteValue ((UINT32) 0x000080CD)
+#define TCM_ORD_NV_WriteValueAuth ((UINT32) 0x000080CE)
+#define TCM_ORD_OIAP ((UINT32) 0x0000800A)
+#define TCM_ORD_OSAP ((UINT32) 0x0000800B)
+#define TCM_ORD_OwnerClear ((UINT32) 0x0000805B)
+#define TCM_ORD_OwnerReadInternalPub ((UINT32) 0x00008081)
+#define TCM_ORD_OwnerReadPubek ((UINT32) 0x0000807D)
+#define TCM_ORD_OwnerSetDisable ((UINT32) 0x0000806E)
+#define TCM_ORD_PCR_Reset ((UINT32) 0x000080C8)
+#define TCM_ORD_PcrRead ((UINT32) 0x00008015)
+#define TCM_ORD_PhysicalDisable ((UINT32) 0x00008070)
+#define TCM_ORD_PhysicalEnable ((UINT32) 0x0000806F)
+#define TCM_ORD_PhysicalSetDeactivated ((UINT32) 0x00008072)
+#define TCM_ORD_Quote ((UINT32) 0x00008016)
+#define TCM_ORD_Quote2 ((UINT32) 0x0000803E)
+#define TCM_ORD_ReadCounter ((UINT32) 0x000080DE)
+#define TCM_ORD_ReadManuMaintPub ((UINT32) 0x00008030)
+#define TCM_ORD_ReadPubek ((UINT32) 0x0000807C)
+#define TCM_ORD_ReleaseCounter ((UINT32) 0x000080DF)
+#define TCM_ORD_ReleaseCounterOwner ((UINT32) 0x000080E0)
+#define TCM_ORD_ReleaseTransportSigned ((UINT32) 0x000080E8)
+#define TCM_ORD_Reset ((UINT32) 0x0000805A)
+#define TCM_ORD_ResetLockValue ((UINT32) 0x00008040)
+#define TCM_ORD_RevokeTrust ((UINT32) 0x00008080)
+#define TCM_ORD_SaveAuthContext ((UINT32) 0x000080B6)
+#define TCM_ORD_SaveContext ((UINT32) 0x000080B8)
+#define TCM_ORD_SaveKeyContext ((UINT32) 0x000080B4)
+#define TCM_ORD_SaveState ((UINT32) 0x00008098)
+#define TCM_ORD_Seal ((UINT32) 0x00008017)
+#define TCM_ORD_Sealx ((UINT32) 0x0000803D)
+#define TCM_ORD_SelfTestFull ((UINT32) 0x00008050)
+#define TCM_ORD_SetCapability ((UINT32) 0x0000803F)
+#define TCM_ORD_SetOperatorAuth ((UINT32) 0x00008074)
+#define TCM_ORD_SetOrdinalAuditStatus ((UINT32) 0x0000808D)
+#define TCM_ORD_SetOwnerInstall ((UINT32) 0x00008071)
+#define TCM_ORD_SetOwnerPointer ((UINT32) 0x00008075)
+#define TCM_ORD_SetRedirection ((UINT32) 0x0000809A)
+#define TCM_ORD_SetTempDeactivated ((UINT32) 0x00008073)
+#define TCM_ORD_SHA1CompleteExtend ((UINT32) 0x000080ED)
+#define TCM_ORD_SHA1Start ((UINT32) 0x000080EA)
+#define TCM_ORD_SHA1Update ((UINT32) 0x000080EB)
+#define TCM_ORD_Sign ((UINT32) 0x0000803C)
+#define TCM_ORD_Startup ((UINT32) 0x00008099)
+#define TCM_ORD_StirRandom ((UINT32) 0x00008047)
+#define TCM_ORD_TakeOwnership ((UINT32) 0x0000800D)
+#define TCM_ORD_Terminate_Handle ((UINT32) 0x00008096)
+#define TCM_ORD_TickStampBlob ((UINT32) 0x000080F2)
+#define TCM_ORD_UnBind ((UINT32) 0x0000801E)
+#define TCM_ORD_Unseal ((UINT32) 0x00008018)
+#define TCM_TSC_ORD_PhysicalPresence ((UINT32) 0x4000800A)
+#define TCM_TSC_ORD_ResetEstablishmentBit ((UINT32) 0x4000800B)
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//********************************************************************** \ No newline at end of file
diff --git a/Core/EM/TCG2/TisLib/sha.h b/Core/EM/TCG2/TisLib/sha.h
new file mode 100644
index 0000000..218bc34
--- /dev/null
+++ b/Core/EM/TCG2/TisLib/sha.h
@@ -0,0 +1,122 @@
+/*++
+
+ Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.
+
+
+ Module Name:
+
+ sha1.h
+
+ Abstract:
+
+ --*/
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/sha.h 1 4/21/14 2:14p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:14p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/sha.h $
+//
+// 1 4/21/14 2:14p Fredericko
+//
+// 1 10/08/13 11:58a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 10/03/13 12:35p Fredericko
+// Sha256 support policy update
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+// [Files] TisLib.cif
+// TisLib.mak
+// TcgTpm12.h
+// TpmLib.h
+// TcgCommon.h
+// ZTEICTcmOrdinals.h
+// TpmLib.c
+// TcgCommon.c
+// TisLib.sdl
+// sha1.h
+// INTTcgAcpi.h
+// TcgPc.h
+// TcmPc.h
+// TcgEfiTpm.h
+// TcgEFI12.h
+//
+// 8 3/29/11 12:24p Fredericko
+//
+// 7 3/28/11 12:14p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+// 6 5/19/10 5:09p Fredericko
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: Sha1.h
+//
+// Description:
+// Header file for sha1.c
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+
+#ifndef _CAL_SHA1_H_
+#define _CAL_SHA1_H_
+
+#include "TcgTpm12.h"
+#include "token.h"
+
+
+typedef TPM_ALGORITHM_ID TCG_ALGORITHM_ID;
+#define TCG_ALG_SHA 0x00000004 // The SHA1 algorithm
+typedef unsigned long u32;
+
+struct SHA1Context {
+ u32 state[5];
+ u32 count[2];
+ unsigned char buffer[64];
+};
+
+typedef struct SHA1Context SHA1_CTX;
+
+
+
+void SHA1Init(struct SHA1Context *context);
+void SHA1Update(struct SHA1Context *context, const void *data, u32 len);
+void SHA1Final(unsigned char digest[20], struct SHA1Context *context);
+
+struct sha256_state {
+ UINT64 length;
+ UINT32 state[8], curlen;
+ UINT8 buf[64];
+};
+
+typedef struct sha256_state SHA2_CTX;
+
+void sha256_init(struct sha256_state *md);
+int sha256_process(struct sha256_state *md, const unsigned char *in, unsigned long inlen);
+int sha256_done(struct sha256_state *md, unsigned char *out);
+
+#endif // _CAL_SHA1_H_
diff --git a/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.c b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.c
new file mode 100644
index 0000000..d1e5c44
--- /dev/null
+++ b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.c
@@ -0,0 +1,125 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/AmiTcmlib/AmiTcmlib.c 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/AmiTcmlib/AmiTcmlib.c $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:59a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 6 4/01/11 9:32a Fredericko
+// Updated function Header
+//
+// 5 3/31/11 4:48p Fredericko
+// Changes for TCG_Legacy support
+//
+// 4 3/29/11 4:51p Fredericko
+// Moved TCM device ID and Vendor ID check to tokens.
+//
+// 3 3/29/11 12:52p Fredericko
+//
+// 2 3/29/11 12:07p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name: AmiTcmlib.c
+//
+// Description:
+// AmiTcmlibrary functions
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+#include "AmiTcmlib.h"
+#include "token.h"
+
+
+TCM_ID_STRUC TCMSupportedArray[NUMBER_OF_SUPPORTED_TCM_DEVICES]={
+ {SUPPORTED_TCM_DEVICE_1_VID,SUPPORTED_TCM_DEVICE_1_DID}, //ZTEIC
+ {SUPPORTED_TCM_DEVICE_2_VID,SUPPORTED_TCM_DEVICE_2_DID} //ZTEIC2
+};
+
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: AutoSupportType
+//
+// Description: verifies support for a TCM module on a platform
+//
+// Input: NONE
+//
+// Output: BOOLEAN
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+extern
+BOOLEAN
+__stdcall AutoSupportType ()
+{
+#if TCG_LEGACY == 0
+ UINTN i=0;
+
+ for(i=0;i<(sizeof(TCMSupportedArray)/sizeof(TCM_ID_STRUC));i++){
+ if((TCMSupportedArray[i].VID == *(UINT16 *)(UINTN)(PORT_TPM_IOMEMBASE + 0xF00)) &&
+ (TCMSupportedArray[i].DID == *(UINT16 *)(UINTN)(PORT_TPM_IOMEMBASE + 0xF02))){
+ return TRUE;
+ }
+ }
+#endif
+ return FALSE;
+}
+
+
+
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.cif b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.cif
new file mode 100644
index 0000000..f6aeaef
--- /dev/null
+++ b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.cif
@@ -0,0 +1,12 @@
+<component>
+ name = "AmiTcmlib"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\Tpm1_2_lib"
+ RefName = "AmiTcmlib"
+[files]
+"AmiTcmlib.sdl"
+"AmiTcmlib.mak"
+"AmiTcmlib.h"
+"AmiTcmlib.dxs"
+"AmiTcmlib.c"
+<endComponent>
diff --git a/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.dxs b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.dxs
new file mode 100644
index 0000000..01c3223
--- /dev/null
+++ b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.dxs
@@ -0,0 +1,68 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/AmiTcmlib/AmiTcmlib.dxs 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/AmiTcmlib/AmiTcmlib.dxs $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:59a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 3/29/11 12:51p Fredericko
+//
+// 2 3/29/11 12:07p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name: AmiTcmlib.dxs
+//
+// Description: AmiTcmlib Dependency file
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+DEPENDENCY_START
+ TRUE
+DEPENDENCY_END
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//********************************************************************** \ No newline at end of file
diff --git a/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.h b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.h
new file mode 100644
index 0000000..570e69b
--- /dev/null
+++ b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.h
@@ -0,0 +1,74 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/AmiTcmlib/AmiTcmlib.h 1 4/21/14 2:15p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:15p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/AmiTcmlib/AmiTcmlib.h $
+//
+// 1 4/21/14 2:15p Fredericko
+//
+// 1 10/08/13 11:59a Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:50p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 3/29/11 12:51p Fredericko
+//
+// 2 3/29/11 12:06p Fredericko
+// [TAG] EIP 54642
+// [Category] Improvement
+// [Description] 1. Checkin Files related to TCG function override
+// 2. Include TCM and TPM auto detection
+// [Files] Affects all TCG files
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name: AmiTcmlib.h
+//
+// Description: Header file for AmiTcmlib.h
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+//Array of supported TCM devices
+#include <efi.h>
+
+typedef struct
+{ UINT16 VID;
+ UINT16 DID;
+} TCM_ID_STRUC;
+
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.mak b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.mak
new file mode 100644
index 0000000..3ef0ed3
--- /dev/null
+++ b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.mak
@@ -0,0 +1,91 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/AmiTcmlib/AmiTcmlib.mak 1 4/21/14 2:15p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:15p $
+#*************************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/AmiTcmlib/AmiTcmlib.mak $
+#
+# 1 4/21/14 2:15p Fredericko
+#
+# 1 10/08/13 11:59a Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 1 7/10/13 5:50p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+#
+# 7 3/29/11 12:51p Fredericko
+#
+# 6 3/29/11 11:52a Fredericko
+# [TAG] EIP 54642
+# [Category] Improvement
+# [Description] 1. Checkin Files related to TCG function override
+# 2. Include TCM and TPM auto detection
+# [Files] Affects all TCG files
+#
+#
+#*************************************************************************
+#<AMI_FHDR_START>
+#
+# Name: AmiTcmlib.mak
+#
+# Description: Make file for AmiTcmlib
+#
+#<AMI_FHDR_END>
+#************************************************************************
+all : $(BUILD_DIR)\AmiTcmlib.lib
+
+#---------------------------------------------------------------------------
+# $(BUILD_DIR)\AmiTcgLibDxe.lib
+#---------------------------------------------------------------------------
+$(BUILD_DIR)\AmiTcmlib.lib : $(BUILD_DIR)\AmiTcmlib.mak MakeAmiTcmlib
+
+$(BUILD_DIR)\AmiTcmlib.mak : $(AMI_TCM_LIB)\AmiTcmlib.cif $(AMI_TCM_LIB)\AmiTcmlib.mak $(BUILD_RULES)
+ $(CIF2MAK) $(AMI_TCM_LIB)\AmiTcmlib.cif $(CIF2MAK_DEFAULTS)
+
+MakeAmiTcmlib:
+!IF "$(PROCESSOR)"=="x64"
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\AmiTcmlib.mak all\
+ TYPE=LIBRARY
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS) BUILD_DIR=$(BUILD_DIR)\IA32\
+ /f $(BUILD_DIR)\AmiTcmlib.mak all\
+ TYPE=PEI_LIBRARY
+!ELSE
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\AmiTcmlib.mak all\
+ TYPE=LIBRARY
+!ENDIF
+
+#---------------------------------------------------------------------------
+
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
diff --git a/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.sdl b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.sdl
new file mode 100644
index 0000000..83cf885
--- /dev/null
+++ b/Core/EM/TCG2/Tpm1_2_lib/AmiTcmlib.sdl
@@ -0,0 +1,71 @@
+TOKEN
+ Name = "AmiTcmLib_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable TCG support in Project"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Master = Yes
+ Token = "TCG2Support" "=" "1"
+End
+
+
+PATH
+ Name = "AMI_TCM_LIB"
+End
+
+MODULE
+ Help = "Includes AmiTcmlib.mak to Project"
+ File = "AmiTcmlib.mak"
+End
+
+TOKEN
+ Name = "SUPPORTED_TCM_DEVICE_1_VID"
+ Value = "19F5h"
+ Help = "Vendor ID of the a supported TCM device"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+
+TOKEN
+ Name = "SUPPORTED_TCM_DEVICE_1_DID"
+ Value = "0001h"
+ Help = "Device ID of the a supported TCM device"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+
+
+TOKEN
+ Name = "SUPPORTED_TCM_DEVICE_2_VID"
+ Value = "1b4eh"
+ Help = "Vendor ID of the a supported TCM device"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+
+TOKEN
+ Name = "SUPPORTED_TCM_DEVICE_2_DID"
+ Value = "0001h"
+ Help = "Device ID of the a supported TCM device"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
+
+
+TOKEN
+ Name = "NUMBER_OF_SUPPORTED_TCM_DEVICES"
+ Value = "0002h"
+ Help = "number of supported tcm devices. Increase this number with addition of new DID and vendor ID"
+ TokenType = Integer
+ TargetEQU = Yes
+ TargetH = Yes
+End
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.c b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.c
new file mode 100644
index 0000000..2203432
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.c
@@ -0,0 +1,132 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollback.c 1 4/21/14 2:18p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:18p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollback.c $
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 1 10/08/13 12:06p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//**********************************************************************
+//<AMI_FHDR_START>
+//---------------------------------------------------------------------------
+// Name: TpmClearOnRollback
+//
+//
+//
+//---------------------------------------------------------------------------
+//<AMI_FHDR_END>
+#include "TpmClearOnRollback.h"
+#include <Protocol/AmiPostMgr.h>
+#include <PPI/FwVersion.h>
+#include <Hob.h>
+#include <Token.h>
+#include <AmiHobs.h>
+
+VOID DrawMessageBox(
+ IN CHAR16 *Caption,
+ IN CHAR16 *Message
+);
+
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Procedure: RecoveryClearTpmBeforeFlash
+//
+// Description:
+// Process TPM clear on Rollback policy
+//
+// Input:
+// VOID
+//
+// Output:
+// VOID
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+VOID RecoveryClearTpmBeforeFlash (VOID){
+ UINT8 ClearResults;
+ AMI_POST_MANAGER_PROTOCOL *TpmClearAmiPostMgr = NULL;
+ FW_VERSION Fid;
+ EFI_EVENT MyEvent;
+ FW_VERSION RecoveryFid;
+ EFI_HOB_HANDOFF_INFO_TABLE *TpmpHit;
+ EFI_GUID myGuidHob = HOB_LIST_GUID;
+ EFI_GUID TpmRecoveryHobGuid = AMI_RECOVERY_IMAGE_HOB_GUID;
+ UINT32 ProjectVersion, NewProjectVersion;
+ EFI_GUID gAmiPostManagerProtocolGuid = \
+ AMI_POST_MANAGER_PROTOCOL_GUID;
+ EFI_STATUS Status;
+
+ TpmpHit = GetEfiConfigurationTable(pST, &myGuidHob);
+ if(TpmpHit != NULL && !EFI_ERROR(FindNextHobByGuid(&TpmRecoveryHobGuid, &TpmpHit))) {
+
+ TpmGetFidFromBuffer(&RecoveryFid, (VOID *)(UINTN)((RECOVERY_IMAGE_HOB*)TpmpHit)->Address);
+ }
+
+ TpmRecoveryGetFidFromFv(&Fid);
+
+ ProjectVersion = Fid.ProjectMajorVersion[0] + Fid.ProjectMajorVersion[1] + Fid.ProjectMajorVersion[2];
+ ProjectVersion <<= 16;
+ ProjectVersion += Fid.ProjectMinorVersion[0] + Fid.ProjectMinorVersion[1] + Fid.ProjectMinorVersion[2];
+
+ NewProjectVersion = RecoveryFid.ProjectMajorVersion[0] + RecoveryFid.ProjectMajorVersion[1] + RecoveryFid.ProjectMajorVersion[2];
+ NewProjectVersion <<= 16;
+ NewProjectVersion += RecoveryFid.ProjectMinorVersion[0] + RecoveryFid.ProjectMinorVersion[1] + RecoveryFid.ProjectMinorVersion[2];
+
+ if(NewProjectVersion < ProjectVersion){
+ ClearResults = ClearTpmBeforeFlash();
+ if(ClearResults == TPM_CLEAR_RESET_REQUIRED)
+ {
+ Status = pBS->LocateProtocol(&gAmiPostManagerProtocolGuid, NULL, &TpmClearAmiPostMgr);
+ if(EFI_ERROR(Status))return;
+
+ if(TpmClearAmiPostMgr != NULL) {
+ Status = TpmClearAmiPostMgr->DisplayInfoBox(L"TPM CLEAR",\
+ L"Caution: A Reset is required to Clear the TPM for Flash Update. Enable Recovery after reset",20, &MyEvent);
+
+ FixedDelay(1000000); //10seconds delay
+ }
+
+ pRS->ResetSystem( EfiResetCold, 0, 0, NULL );
+ }
+ }
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.cif b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.cif
new file mode 100644
index 0000000..62c2814
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.cif
@@ -0,0 +1,17 @@
+<component>
+ name = "TpmClearOnRollback"
+ category = ModulePart
+ LocalRoot = "Core\EM\TCG2\TpmClearOnRollback\"
+ RefName = "TpmClearOnRollback"
+[files]
+"TpmClearOnRollback.c"
+"TpmClearOnRollback.h"
+"TpmClearOnRollback.sdl"
+"TpmClearOnRollback.mak"
+"TpmClearOnRollback.dxs"
+"TpmClearOnRollbackSmiFlash.c"
+"TpmClearOnRollbackWrapperLib.c"
+"TpmClearOnRollbackWrapperLib.h"
+[parts]
+"AmiTpmClearOnRollbackProtocol"
+<endComponent>
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.dxs b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.dxs
new file mode 100644
index 0000000..c5f6e32
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.dxs
@@ -0,0 +1,75 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollback.dxs 1 4/21/14 2:18p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:18p $
+//*************************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollback.dxs $
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 1 10/08/13 12:06p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+// 3 7/25/11 3:21a Fredericko
+// [TAG] EIP65177
+// [Category] Spec Update
+// [Severity] Minor
+// [Description] TCG Ppi Sec ver 1.2 update
+//
+// 2 5/20/10 8:54a Fredericko
+//
+// Included File Header
+// Included File Revision History
+// EIP 37653
+//
+//*************************************************************************
+//<AMI_FHDR_START>
+//
+// Name: TCGSmm.dxs
+//
+// Description:
+// Dependency for TcgSmm
+//
+//<AMI_FHDR_END>
+//*************************************************************************
+#include <Protocol\SmmBase2.h>
+
+DEPENDENCY_START
+ EFI_SMM_BASE2_PROTOCOL_GUID
+DEPENDENCY_END
+//*************************************************************************
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.h b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.h
new file mode 100644
index 0000000..23be079
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.h
@@ -0,0 +1,69 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollback.h 1 4/21/14 2:18p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:18p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollback.h $
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 1 10/08/13 12:06p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name:
+//
+// Description:
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+#ifndef _TPM_CLEAR_ON_ROLLBACK_H
+#define _TPM_CLEAR_ON_ROLLBACK_H
+
+#include <AmiDxeLib.h>
+#include <Protocol\TcgService.h>
+#include <TCGMisc.h>
+#include <Protocol\SmmBase2.h>
+#include <Protocol\AmiTpmClearOnRollbackProtocol.h>
+#include "TpmClearOnRollbackWrapperLib.h"
+
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.mak b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.mak
new file mode 100644
index 0000000..f0423be
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.mak
@@ -0,0 +1,107 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2011, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+
+#**********************************************************************
+# $Header: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollback.mak 1 4/21/14 2:18p Fredericko $
+#
+# $Revision: 1 $
+#
+# $Date: 4/21/14 2:18p $
+#**********************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollback.mak $
+#
+# 1 4/21/14 2:18p Fredericko
+#
+# 1 10/08/13 12:06p Fredericko
+# Initial Check-In for Tpm-Next module
+#
+# 2 10/03/13 2:48p Fredericko
+#
+# 1 7/10/13 5:57p Fredericko
+# [TAG] EIP120969
+# [Category] New Feature
+# [Description] TCG (TPM20)
+#
+#
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name:
+#
+# Description:
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+all : BuildTpmClearOnRollbackWrapperLib TPMCLEARONROLLBACK
+
+TPMCLEARONROLLBACK : $(BUILD_DIR)\TpmClearOnRollback.mak TpmClearRollBackSmmBin
+
+BuildTpmClearOnRollbackWrapperLib: $(BUILD_DIR)\TpmClearOnRollback.mak TpmClearOnRollbackWrapperLibBin
+$(TpmClearOnRollbackWrapperLib): BuildTpmClearOnRollbackWrapperLib
+
+$(BUILD_DIR)\TpmClearOnRollback.mak : $(TPMCLEARONROLLBACK_DIR)\$(@B).cif $(TPMCLEARONROLLBACK_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(TPMCLEARONROLLBACK_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+TCGCLEAR_CFLAGS=$(CFLAGS) \
+ /I$(TCG_DIR)\
+ /I$(TCG_DIR)\Common\
+ /I$(PROJECT_DIR)\Include\Protocol\
+ /I$(TCG_DIR)\Protocol
+
+
+TPM_CLEAR_ON_ROLLBACK_WRAPPEER_OBJS = \
+$(BUILD_DIR)\$(TPMCLEARONROLLBACK_DIR)\TpmClearOnRollbackWrapperLib.obj
+
+TpmClearOnRollbackWrapperLibBin: $(tcgLibLite)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\TpmClearOnRollback.mak all\
+ "CFLAGS=$(TCGCLEAR_CFLAGS)" \
+ "OBJECTS=$(TPM_CLEAR_ON_ROLLBACK_WRAPPEER_OBJS)"\
+ TYPE=LIBRARY \
+ LIBRARY_NAME=$(TpmClearOnRollbackWrapperLib)
+
+TCGCLEAR_OBJECTS = \
+$(BUILD_DIR)\$(TPMCLEARONROLLBACK_DIR)\TpmClearOnRollbackSmiFlash.obj
+
+ReFlashBin: $(BUILD_DIR)\$(TCG)\TpmClearOnRollback.obj $(TpmClearOnRollbackWrapperLib)
+
+$(BUILD_DIR)\$(TCG)\TpmClearOnRollback.obj : $(TPMCLEARONROLLBACK_DIR)\TpmClearOnRollback.obj
+ $(CC) $(TCGCLEAR_CFLAGS) /Fo$(BUILD_DIR)\$(TCG)\TpmClearOnRollback.obj $(TPMCLEARONROLLBACK_DIR)\TpmClearOnRollback.c
+
+TpmClearRollBackSmmBin : $(TpmClearOnRollbackWrapperLib) $(AMIDXELIB)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS) \
+ /f $(BUILD_DIR)\TpmClearOnRollback.mak all \
+ GUID=FD2CB3F1-9520-4c24-BCB3-2C73F0C2B7EC \
+ "CFLAGS=$(TCGCLEAR_CFLAGS)" \
+ ENTRY_POINT=TpmClearRollBackSmmInit \
+ TYPE=BS_DRIVER \
+ "OBJECTS=$(TCGCLEAR_OBJECTS)"\
+ DEPEX1=$(TPMCLEARONROLLBACK_DIR)\TpmClearOnRollback.DXS \
+ COMPRESS=1 \
+
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1985-2010, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.sdl b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.sdl
new file mode 100644
index 0000000..b616dae
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollback.sdl
@@ -0,0 +1,41 @@
+TOKEN
+ Name = "TPMCLEARONROLLBACK_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable TcgPlatformSetupPolicy support in Project"
+ TokenType = Boolean
+ TargetH = Yes
+ TargetEQU = Yes
+ TargetMAK = Yes
+ Master = Yes
+ Token = "TPM12Enabled" "!=" "0"
+End
+
+
+PATH
+ Name = "TPMCLEARONROLLBACK_DIR"
+End
+
+MODULE
+ Help = "Includes AmtPlatformPolicy.mak to Project"
+ File = "TpmClearOnRollback.mak"
+End
+
+TOKEN
+ Name = "TpmClearOnRollbackWrapperLib"
+ Value = "$(BUILD_DIR)\TpmClearOnRollbackWrapperLib.lib"
+ TokenType = Expression
+ TargetMAK = Yes
+End
+
+
+ELINK
+ Name = "RecoveryClearTpmBeforeFlash,"
+ Parent = "OemBeforeFlashUpdateList"
+ InvokeOrder = AfterParent
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\TpmClearOnRollback.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End \ No newline at end of file
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackSmiFlash.c b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackSmiFlash.c
new file mode 100644
index 0000000..720940b
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackSmiFlash.c
@@ -0,0 +1,160 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollbackSmiFlash.c 1 4/21/14 2:18p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:18p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollbackSmiFlash.c $
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 1 10/08/13 12:06p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//**********************************************************************
+//<AMI_FHDR_START>
+//---------------------------------------------------------------------------
+// Name:
+//
+//
+//
+//---------------------------------------------------------------------------
+//<AMI_FHDR_END>
+#include "TpmClearOnRollback.h"
+#include <Protocol/AmiPostMgr.h>
+
+CLEAR_TPM_ROLLBACK_PROTOCOL *PrivateProtocol;
+EFI_SMM_SYSTEM_TABLE2 *mSmst;
+static FW_VERSION Fid;
+
+
+UINT8 SmiFlashClearTpmBeforeFlash (){
+ return(ClearTpmBeforeFlash());
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: InstallTpmClearProtocolInSmm
+//
+// Description: InstallTcgSmmFlash Protocol
+//
+//
+// Input: IN EFI_HANDLE ImageHandle,
+// IN EFI_SYSTEM_TABLE *SystemTable
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS InstallTpmClearProtocolInSmm(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ EFI_SMM_BASE2_PROTOCOL *SmmBase;
+ EFI_HANDLE Handle=NULL;
+ EFI_STATUS Status;
+ EFI_GUID TpmRollbackSmmGuid = \
+ AMI_TPM_ROLLBACK_SMM_PROTOCOL_GUID;
+
+ Status = pBS->LocateProtocol (&gEfiSmmBase2ProtocolGuid, NULL, &SmmBase);
+ if((EFI_ERROR(Status)) || (SmmBase == NULL)){
+ return Status;
+ }
+
+ Status = SmmBase->GetSmstLocation(SmmBase, &mSmst);
+ if(EFI_ERROR(Status)){
+ return Status;
+ }
+
+ Status = mSmst->SmmAllocatePool (
+ EfiRuntimeServicesData,
+ sizeof (CLEAR_TPM_ON_ROLLBACK),
+ &PrivateProtocol
+ );
+
+ if((EFI_ERROR(Status)) || (PrivateProtocol == NULL)){
+ return Status;
+ }
+
+ TpmRecoveryGetFidFromFv(&Fid);
+
+ PrivateProtocol->ClearTpmOnRollBack = (VOID *)&SmiFlashClearTpmBeforeFlash;
+
+ Status = mSmst->SmmInstallProtocolInterface( &Handle, \
+ &TpmRollbackSmmGuid, \
+ EFI_NATIVE_INTERFACE, \
+ PrivateProtocol );
+
+ return Status;
+}
+
+
+
+//****************************************************** ****************
+//<AMI_PHDR_START>
+//
+// Procedure: TpmClearRollBackSmmInit
+//
+// Description: Entry point for subcomponent
+//
+// Input: IN EFI_HANDLE ImageHandle,
+// IN EFI_SYSTEM_TABLE *SystemTable
+//
+// Output: EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS TpmClearRollBackSmmInit(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable )
+{
+ InitAmiLib( ImageHandle, SystemTable );
+
+ return InitSmmHandler( ImageHandle, SystemTable, InstallTpmClearProtocolInSmm, NULL );
+}
+
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.c b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.c
new file mode 100644
index 0000000..dd71a11
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.c
@@ -0,0 +1,584 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.c 2 4/21/14 3:17p Fredericko $
+//
+// $Revision: 2 $
+//
+// $Date: 4/21/14 3:17p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.c $
+//
+// 2 4/21/14 3:17p Fredericko
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 1 10/08/13 12:06p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//**********************************************************************
+//<AMI_FHDR_START>
+//---------------------------------------------------------------------------
+// Name:
+//
+//
+//
+//---------------------------------------------------------------------------
+//<AMI_FHDR_END>
+#include "TpmClearOnRollback.h"
+#include "TpmClearOnRollbackWrapperLib.h"
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Procedure: TpmRecoveryGetFidFromFv
+//
+// Description:
+// Finds FID information in the Flash
+//
+// Input:
+//
+//
+// Output:
+//
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+EFI_STATUS TpmRecoveryGetFidFromFv(
+ OUT VOID *Fid
+)
+{
+ static EFI_GUID FidFileName = FID_FFS_FILE_NAME_GUID;
+ EFI_STATUS Status;
+ EFI_HANDLE *FvHandle;
+ UINTN FvCount;
+ UINTN i;
+ UINTN BufferSize;
+ VOID *Buffer;
+
+ Status = pBS->LocateHandleBuffer(ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &FvCount, &FvHandle);
+ if (EFI_ERROR(Status))
+ return Status;
+
+ for(i = 0; i < FvCount; i++)
+ {
+ EFI_FIRMWARE_VOLUME_PROTOCOL *Fv;
+ UINT32 AuthStatus;
+ Status = pBS->HandleProtocol(FvHandle[i], &gEfiFirmwareVolume2ProtocolGuid, &Fv);
+ if (EFI_ERROR(Status))
+ continue;
+ Buffer = 0;
+ BufferSize = 0;
+ Status = Fv->ReadSection(Fv, &FidFileName, EFI_SECTION_FREEFORM_SUBTYPE_GUID, 0, &Buffer, &BufferSize, &AuthStatus);
+ TRACE((-1, "extracted section with guid %g\n", (EFI_GUID *)Buffer));
+ if (!EFI_ERROR(Status)) {
+ (UINT8 *)Buffer += sizeof(EFI_GUID);
+ MemCpy(Fid, Buffer, sizeof(FW_VERSION));
+ (UINT8 *)Buffer -= sizeof(EFI_GUID);
+ pBS->FreePool(Buffer);
+ return EFI_SUCCESS;
+ }
+ }
+ pBS->FreePool(FvHandle);
+ return EFI_NOT_FOUND;
+}
+
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Procedure: TpmGetFidFromBuffer
+//
+// Description:
+// Finds FID information in provided buffer
+//
+// Input:
+//
+//
+// Output:
+//
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+EFI_STATUS TpmGetFidFromBuffer(
+ OUT VOID *Fid,
+ IN VOID *Buffer
+)
+{
+ static EFI_GUID FidSectionGuid = FID_FFS_FILE_SECTION_GUID;
+ UINT32 Signature;
+ UINT32 *SearchPointer;
+
+ SearchPointer = (UINT32 *)((UINT8 *)Buffer - sizeof(EFI_GUID) + FLASH_SIZE);
+ Signature = FidSectionGuid.Data1;
+
+ do {
+ if(*SearchPointer == Signature) {
+ if(!guidcmp(&FidSectionGuid, (EFI_GUID *)SearchPointer)) {
+ (UINT8 *)SearchPointer += sizeof(EFI_GUID);
+ MemCpy(Fid, SearchPointer, sizeof(FW_VERSION));
+ return EFI_SUCCESS;
+ }
+ }
+ } while(SearchPointer-- >= (UINT32 *)Buffer);
+
+ return EFI_NOT_FOUND;
+}
+
+
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+// Procedure: SendTpmCommandRecovery
+//
+// Description:
+// Generic send TPM Transaction
+//
+// Input:
+//
+//
+// Output:
+//
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+EFI_STATUS SendTpmCommandRecovery(UINT8 *Cmd, UINTN CmdSize,
+ UINT8 *RetBuff, UINTN RetBuffSize)
+{
+ EFI_STATUS Status;
+ TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1];
+
+ InBuffer[0].Buffer = Cmd;
+ InBuffer[0].Size = CmdSize;
+ OutBuffer[0].Buffer = RetBuff;
+ OutBuffer[0].Size = RetBuffSize;
+
+ Status = TpmLibPassThrough(((TPM_1_2_REGISTERS_PTR)(UINTN)TPM_BASE_ADDRESS),
+ sizeof (InBuffer)/sizeof (*InBuffer),
+ InBuffer,
+ sizeof (OutBuffer) / sizeof (*OutBuffer),
+ OutBuffer);
+
+ return Status;
+
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: RecoverySetPhysicalPresence
+//
+// Description:
+//
+// Input:
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS RecoverySetPhysicalPresence()
+{
+ EFI_STATUS Status;
+ PHYSICAL_PRESENCE_CMD PpCmd;
+ TPM_1_2_RET_HEADER retHeader;
+
+
+ PpCmd.Hdr.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ PpCmd.Hdr.ParamSize = TPM_H2NL( sizeof (PHYSICAL_PRESENCE_CMD));
+ PpCmd.Hdr.Ordinal = TPM_H2NL( TSC_ORD_PhysicalPresence );
+ PpCmd.Data = TPM_H2NS(TPM_PHYSICAL_PRESENCE_CMD_ENABLE );
+
+ MemSet(&retHeader, sizeof(TPM_1_2_RET_HEADER), 0);
+
+ Status = SendTpmCommandRecovery((UINT8 *)&PpCmd, sizeof(PHYSICAL_PRESENCE_CMD),
+ (UINT8 *)&retHeader, sizeof(TPM_1_2_RET_HEADER));
+
+ //don't care about error case on setting physical presence CMD type
+ //care about actual physical presence failure
+ MemSet(&retHeader, sizeof(TPM_1_2_RET_HEADER), 0);
+
+ PpCmd.Data = TPM_H2NS(TPM_PHYSICAL_PRESENCE_PRESENT);
+
+ Status = SendTpmCommandRecovery((UINT8 *)&PpCmd, sizeof(PHYSICAL_PRESENCE_CMD),
+ (UINT8 *)&retHeader, sizeof(TPM_1_2_RET_HEADER));
+
+ if(retHeader.RetCode == 0)
+ {
+ return EFI_SUCCESS;
+ }
+
+ return EFI_SECURITY_VIOLATION;
+
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: RecoveryEnableActivate
+//
+// Description:
+//
+// Input:
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS RecoveryEnableActivate()
+{
+ EFI_STATUS Status;
+ DATA_CMD Command;
+ TPM_1_2_CMD_HEADER cmdEnable;
+ TPM_1_2_RET_HEADER retHeader;
+
+ cmdEnable.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdEnable.ParamSize = TPM_H2NL( sizeof (TPM_1_2_CMD_HEADER));
+ cmdEnable.Ordinal = TPM_H2NL( TPM_ORD_PhysicalEnable );
+
+ MemSet(&retHeader, sizeof(TPM_1_2_RET_HEADER), 0);
+
+ Status = SendTpmCommandRecovery((UINT8 *)&cmdEnable, sizeof(TPM_1_2_CMD_HEADER),
+ (UINT8 *)&retHeader, sizeof(TPM_1_2_RET_HEADER));
+
+ if(!EFI_ERROR(Status) && retHeader.RetCode == 0){
+ Command.Hdr.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ Command.Hdr.ParamSize = TPM_H2NL( sizeof (DATA_CMD));
+ Command.Hdr.Ordinal = TPM_H2NL( TPM_ORD_PhysicalSetDeactivated );
+ Command.Data = 0x0;
+
+ MemSet(&retHeader, sizeof(TPM_1_2_RET_HEADER), 0);
+
+ Status = SendTpmCommandRecovery((UINT8 *)&Command, sizeof(DATA_CMD),
+ (UINT8 *)&retHeader, sizeof(TPM_1_2_RET_HEADER));
+
+ if(retHeader.RetCode == 0)
+ {
+ return EFI_SUCCESS;
+ }
+ }
+
+ return EFI_SECURITY_VIOLATION;
+
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: RecoverySendClearCmd
+//
+// Description:
+//
+// Input:
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+UINT8 RecoverySendClearCmd()
+{
+ EFI_STATUS Status;
+ TPM_1_2_CMD_HEADER cmdClear;
+ TPM_1_2_RET_HEADER retHeader;
+
+ cmdClear.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdClear.ParamSize = TPM_H2NL( sizeof (TPM_1_2_CMD_HEADER));
+ cmdClear.Ordinal = TPM_H2NL( TPM_ORD_ForceClear );
+
+ MemSet(&retHeader, sizeof(TPM_1_2_RET_HEADER), 0);
+
+ Status = SendTpmCommandRecovery((UINT8 *)&cmdClear, sizeof(TPM_1_2_CMD_HEADER),
+ (UINT8 *)&retHeader, sizeof(TPM_1_2_RET_HEADER));
+
+ if(retHeader.RetCode == 0)
+ {
+ return TPM_CLEAR_SUCCESSFUL;
+ }else if((retHeader.RetCode == TPM_H2NL(DISABLED))||
+ (retHeader.RetCode == TPM_H2NL(DEACTIVATED))){
+ //we need to send enable and activate command
+ //reset and then clear.
+ Status = RecoveryEnableActivate();
+
+ if(!EFI_ERROR(Status)){
+ return TPM_CLEAR_RESET_REQUIRED;
+ }
+ }
+
+ return TPM_FATAL_CONTINUE_FLASH;
+
+}
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: RecoverySendStartUpCmd
+//
+// Description:
+//
+// Input:
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS RecoverySendStartUpCmd()
+{
+ EFI_STATUS Status;
+ TPM_1_2_CMD_STARTUP cmdStartup;
+ TPM_1_2_RET_HEADER retHeader;
+ TPM_STARTUP_TYPE TpmSt = TPM_ST_CLEAR;
+
+ cmdStartup.Header.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdStartup.Header.ParamSize = TPM_H2NL( sizeof (cmdStartup));
+ cmdStartup.Header.Ordinal = TPM_H2NL( TPM_ORD_Startup );
+ cmdStartup.StartupType = TPM_H2NS( TpmSt );
+
+ MemSet(&retHeader, sizeof(TPM_1_2_RET_HEADER), 0);
+
+ Status = SendTpmCommandRecovery((UINT8 *)&cmdStartup, sizeof(TPM_1_2_CMD_STARTUP),
+ (UINT8 *)&retHeader, sizeof(TPM_1_2_RET_HEADER));
+
+ if(retHeader.RetCode == 0)
+ {
+ return EFI_SUCCESS;
+ }
+
+ return EFI_DEVICE_ERROR;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: GetCapabilityCmd
+//
+// Description:
+//
+// Input:
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS GetCapabilityCmd(TPM_Capabilities_PermanentFlag *PermFlags)
+{
+ EFI_STATUS Status = EFI_ABORTED;
+ BOOLEAN Support = FALSE;
+ TPM_GetCapabilities_Input cmdGetCap;
+
+ cmdGetCap.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdGetCap.ParamSize = TPM_H2NL( sizeof (cmdGetCap));
+
+ if(AutoSupportType()){
+ //not supported
+ return EFI_SUCCESS;
+ }else{
+ cmdGetCap.CommandCode = TPM_H2NL( TPM_ORD_GetCapability );
+ cmdGetCap.caparea = TPM_H2NL( TPM_CAP_FLAG );
+ }
+
+ cmdGetCap.subCapSize = TPM_H2NL( 4 ); // subCap is always 32bit long
+ cmdGetCap.subCap = TPM_H2NL( TPM_CAP_FLAG_PERMANENT );
+
+ Status = SendTpmCommandRecovery((UINT8 *)&cmdGetCap, sizeof(TPM_GetCapabilities_Input),
+ (UINT8 *)PermFlags, sizeof(TPM_Capabilities_PermanentFlag));
+
+ if(PermFlags->RetCode == TPM_H2NL(INVALID_POSTINIT))
+ {
+ return EFI_NOT_READY;
+ }
+
+ if(PermFlags->RetCode == 0){
+ return EFI_SUCCESS;
+ }
+
+ return EFI_DEVICE_ERROR;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: GetVolatileFlags
+//
+// Description:
+//
+// Input:
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS GetVolatileFlags(TPM_VOLATILE_FLAGS *VolatileFlags)
+{
+ EFI_STATUS Status = EFI_ABORTED;
+ BOOLEAN Support = FALSE;
+ TPM_GetCapabilities_Input cmdGetCap;
+
+ cmdGetCap.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND );
+ cmdGetCap.ParamSize = TPM_H2NL( sizeof (cmdGetCap));
+
+ if(AutoSupportType()){
+ return EFI_SUCCESS;
+ }else{
+ cmdGetCap.CommandCode = TPM_H2NL( TPM_ORD_GetCapability );
+ cmdGetCap.caparea = TPM_H2NL( TPM_CAP_FLAG );
+ }
+
+ cmdGetCap.subCapSize = TPM_H2NL( 4 ); // subCap is always 32bit long
+ cmdGetCap.subCap = TPM_H2NL( TPM_CAP_FLAG_VOLATILE );
+
+ Status = SendTpmCommandRecovery((UINT8 *)&cmdGetCap, sizeof(TPM_GetCapabilities_Input),
+ (UINT8 *)VolatileFlags, sizeof(TPM_VOLATILE_FLAGS));
+
+ if(VolatileFlags->RetCode == TPM_H2NL(INVALID_POSTINIT))
+ {
+ return EFI_NOT_READY;
+ }
+
+ if(VolatileFlags->RetCode == 0){
+ return EFI_SUCCESS;
+ }
+
+ return EFI_DEVICE_ERROR;
+}
+
+
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: ClearTpmBeforeFlash
+//
+// Description:
+//
+// Input:
+//
+// Output:
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes:
+//<AMI_PHDR_END>
+//**********************************************************************
+UINT8 ClearTpmBeforeFlash()
+{
+ TPM_Capabilities_PermanentFlag PermFlags;
+ UINT8 Result=0;
+ EFI_STATUS Status;
+ TPM_VOLATILE_FLAGS TpmVolatileFlags;
+
+ if(AutoSupportType())return TPM_CLEAR_SUCCESSFUL;
+
+ Status = IsTpmPresent((TPM_1_2_REGISTERS_PTR)( UINTN ) TPM_BASE_ADDRESS);
+ if(EFI_ERROR(Status)){
+ return TPM_CLEAR_SUCCESSFUL;
+ }
+
+ //else we have a TPM need to process to clear
+ TisRequestLocality((TPM_1_2_REGISTERS_PTR)( UINTN ) TPM_BASE_ADDRESS);
+
+ Status = GetCapabilityCmd(&PermFlags);
+ if(Status == EFI_NOT_READY)
+ {
+ Status = RecoverySendStartUpCmd();
+ if(EFI_ERROR(Status))
+ {
+ return TPM_FATAL_CONTINUE_FLASH;
+ }
+ }
+
+ if(EFI_ERROR(Status))return TPM_FATAL_CONTINUE_FLASH;
+
+ Status = RecoverySetPhysicalPresence();
+ if(!EFI_ERROR(Status))
+ {
+ Status = GetVolatileFlags(&TpmVolatileFlags);
+ if(!EFI_ERROR(Status)){
+ if(TpmVolatileFlags.physicalPresenceLock){
+ //we need to go into manufacturing mode\special mode
+ //to skip physical presence lock; Return we failed
+ //to clear TPM and flashing should be discontinued.
+ return TPM_FATAL_DISCONTINUE_FLASH;
+ }
+ }
+ Result = RecoverySendClearCmd();
+ }else{
+ if(EFI_ERROR(Status))return TPM_FATAL_CONTINUE_FLASH;
+ }
+
+ TisReleaseLocality((TPM_1_2_REGISTERS_PTR)( UINTN ) TPM_BASE_ADDRESS);
+
+ return Result;
+}
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2010, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.h b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.h
new file mode 100644
index 0000000..5c32d15
--- /dev/null
+++ b/Core/EM/TCG2/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.h
@@ -0,0 +1,198 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.h 1 4/21/14 2:18p Fredericko $
+//
+// $Revision: 1 $
+//
+// $Date: 4/21/14 2:18p $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/TCG2/Common/TpmClearOnRollback/TpmClearOnRollbackWrapperLib.h $
+//
+// 1 4/21/14 2:18p Fredericko
+//
+// 1 10/08/13 12:06p Fredericko
+// Initial Check-In for Tpm-Next module
+//
+// 1 7/10/13 5:57p Fredericko
+// [TAG] EIP120969
+// [Category] New Feature
+// [Description] TCG (TPM20)
+//
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//----------------------------------------------------------------------------
+//
+// Name:
+//
+// Description:
+//
+//----------------------------------------------------------------------------
+//<AMI_FHDR_END>
+#ifndef _TPM_CLEAR_ON_ROLLBACK_WRAPPER_H
+#define _TPM_CLEAR_ON_ROLLBACK_WRAPPER_H
+
+#include <AmiDxeLib.h>
+#include <Protocol\TcgService.h>
+#include <TCGMisc.h>
+#include <Protocol\SmmBase2.h>
+#include <Protocol\AmiTpmClearOnRollbackProtocol.h>
+#include <PPI/FwVersion.h>
+#include <Hob.h>
+#include <Token.h>
+#include <AmiHobs.h>
+
+#define FID_FFS_FILE_NAME_GUID \
+ { 0x3fd1d3a2, 0x99f7, 0x420b, 0xbc, 0x69, 0x8b, 0xb1, 0xd4, 0x92, 0xa3, 0x32 }
+
+#define FID_FFS_FILE_SECTION_GUID \
+ { 0x2EBE0275, 0x6458, 0x4AF9, 0x91, 0xED, 0xD3, 0xF4, 0xED, 0xB1, 0x00, 0xAA }
+
+#define TPM_BASE_ADDRESS 0xfed40000
+#define BASE 0x0
+#define INVALID_POSTINIT ((TPM_RESULT) (BASE + 38))
+#define DISABLED ((TPM_RESULT) (BASE + 7))
+#define DEACTIVATED ((TPM_RESULT) (BASE + 6))
+
+#define TPM_H2NS( x ) \
+ (((UINT16)(x) << 8) | ((UINT16)(x) >> 8))
+#define TPM_H2NL( x ) \
+ (UINT32)((((UINT32)(x)) >> 24) \
+ | (((x) >> 8) & 0xff00) \
+ | ((x) << 24) \
+ | (((x) & 0xff00) << 8))
+
+#define TPM_N2HS( x ) TPM_H2NS( x )
+#define TPM_N2HL( x ) TPM_H2NL( x )
+
+#pragma pack(1)
+
+typedef struct _TPM_1_2_REGISTERS {
+ UINT8 Access; // 0
+ UINT8 Reserved1[7]; // 1
+ UINT32 IntEnable; // 8
+ UINT8 IntVector; // 0ch
+ UINT8 Reserved2[3]; // 0dh
+ UINT32 IntSts; // 10h
+ UINT32 IntfCapability; // 14h
+ UINT8 Sts; // 18h
+ UINT16 BurstCount; // 19h
+ UINT8 Reserved3[9];
+ UINT32 DataFifo; // 24h
+ UINT8 Reserved4[0xed8]; // 28h
+ UINT16 Vid; // 0f00h
+ UINT16 Did; // 0f02h
+ UINT8 Rid; // 0f04h
+ UINT8 TcgDefined[0x7b]; // 0f05h
+ UINT32 LegacyAddress1; // 0f80h
+ UINT32 LegacyAddress1Ex; // 0f84h
+ UINT32 LegacyAddress2; // 0f88h
+ UINT32 LegacyAddress2Ex; // 0f8ch
+ UINT8 VendorDefined[0x70];// 0f90h
+} TPM_1_2_REGISTERS;
+
+typedef volatile TPM_1_2_REGISTERS *TPM_1_2_REGISTERS_PTR;
+
+typedef struct _TPM_TRANSMIT_BUFFER {
+ VOID *Buffer;
+ UINTN Size;
+} TPM_TRANSMIT_BUFFER;
+
+typedef struct _TPM_1_2_CMD_HEADER
+{
+ TPM_TAG Tag;
+ UINT32 ParamSize;
+ TPM_COMMAND_CODE Ordinal;
+} TPM_1_2_CMD_HEADER;
+
+typedef struct _TPM_1_2_RET_HEADER
+{
+ TPM_TAG Tag;
+ UINT32 ParamSize;
+ TPM_RESULT RetCode;
+} TPM_1_2_RET_HEADER;
+
+typedef struct _TPM_1_2_CMD_STARTUP
+{
+ TPM_1_2_CMD_HEADER Header;
+ TPM_STARTUP_TYPE StartupType;
+} TPM_1_2_CMD_STARTUP;
+
+typedef struct _PHYSICAL_PRESENCE_CMD{
+ TPM_1_2_CMD_HEADER Hdr;
+ UINT16 Data;
+} PHYSICAL_PRESENCE_CMD;
+
+typedef struct _DATA_CMD{
+ TPM_1_2_CMD_HEADER Hdr;
+ UINT8 Data;
+} DATA_CMD;
+
+#pragma pack()
+
+EFI_STATUS
+__stdcall IsTpmPresent (
+ IN TPM_1_2_REGISTERS_PTR TpmReg );
+
+EFI_STATUS
+__stdcall TisReleaseLocality (
+ IN TPM_1_2_REGISTERS_PTR TpmReg );
+
+EFI_STATUS
+__stdcall TisRequestLocality (
+ IN TPM_1_2_REGISTERS_PTR TpmReg );
+
+EFI_STATUS
+__stdcall TpmLibPassThrough (
+ IN TPM_1_2_REGISTERS_PTR TpmReg,
+ IN UINTN NoInputBuffers,
+ IN TPM_TRANSMIT_BUFFER *InputBuffers,
+ IN UINTN NoOutputBuffers,
+ IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers );
+
+BOOLEAN
+__stdcall AutoSupportType ();
+
+EFI_STATUS TpmRecoveryGetFidFromFv(
+ OUT VOID *Fid
+);
+
+EFI_STATUS TpmGetFidFromBuffer(
+ OUT VOID *Fid,
+ IN VOID *Buffer
+);
+
+UINT8 ClearTpmBeforeFlash();
+
+void
+__stdcall
+FixedDelay(UINT32 dCount);
+
+#endif
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//************************************************************************* \ No newline at end of file