summaryrefslogtreecommitdiff
path: root/Core/EM/TCG2/Common
diff options
context:
space:
mode:
Diffstat (limited to 'Core/EM/TCG2/Common')
-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
69 files changed, 20458 insertions, 0 deletions
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 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************