/** @file\r
PTP (Platform TPM Profile) CRB (Command Response Buffer) interface used by dTPM2.0 library.\r
\r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
@retval FALSE TPM PTP is not found.\r
**/\r
BOOLEAN\r
-IsPtpPresence (\r
+Tpm2IsPtpPresence (\r
IN VOID *Reg\r
)\r
{\r
{\r
EFI_STATUS Status;\r
\r
- if (!IsPtpPresence (CrbReg)) {\r
+ if (!Tpm2IsPtpPresence (CrbReg)) {\r
return EFI_NOT_FOUND;\r
}\r
\r
PTP_TIMEOUT_MAX\r
);\r
if (EFI_ERROR (Status)) {\r
- Status = EFI_DEVICE_ERROR;\r
- goto Exit;\r
+ //\r
+ // Command Completion check timeout. Cancel the currently executing command by writing TPM_CRB_CTRL_CANCEL,\r
+ // Expect TPM_RC_CANCELLED or successfully completed response.\r
+ //\r
+ MmioWrite32((UINTN)&CrbReg->CrbControlCancel, PTP_CRB_CONTROL_CANCEL);\r
+ Status = PtpCrbWaitRegisterBits (\r
+ &CrbReg->CrbControlStart,\r
+ 0,\r
+ PTP_CRB_CONTROL_START,\r
+ PTP_TIMEOUT_B\r
+ );\r
+ MmioWrite32((UINTN)&CrbReg->CrbControlCancel, 0);\r
+\r
+ if (EFI_ERROR(Status)) {\r
+ //\r
+ // Still in Command Execution state. Try to goIdle, the behavior is agnostic.\r
+ //\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Exit;\r
+ }\r
}\r
\r
//\r
@return PTP interface type.\r
**/\r
PTP_INTERFACE_TYPE\r
-GetPtpInterface (\r
+Tpm2GetPtpInterface (\r
IN VOID *Register\r
)\r
{\r
PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability;\r
\r
- if (!IsPtpPresence (Register)) {\r
+ if (!Tpm2IsPtpPresence (Register)) {\r
return PtpInterfaceMax;\r
}\r
//\r
UINT8 Rid;\r
PTP_INTERFACE_TYPE PtpInterface;\r
\r
- if (!IsPtpPresence (Register)) {\r
+ if (!Tpm2IsPtpPresence (Register)) {\r
return ;\r
}\r
\r
Vid = 0xFFFF;\r
Did = 0xFFFF;\r
Rid = 0xFF;\r
- PtpInterface = GetPtpInterface (Register);\r
+ PtpInterface = Tpm2GetPtpInterface (Register);\r
DEBUG ((EFI_D_INFO, "PtpInterface - %x\n", PtpInterface));\r
switch (PtpInterface) {\r
case PtpInterfaceCrb:\r
{\r
PTP_INTERFACE_TYPE PtpInterface;\r
\r
- PtpInterface = GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+ PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
switch (PtpInterface) {\r
case PtpInterfaceCrb:\r
return PtpCrbTpmCommand (\r
{\r
PTP_INTERFACE_TYPE PtpInterface;\r
\r
- PtpInterface = GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
+ PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
switch (PtpInterface) {\r
case PtpInterfaceCrb:\r
return PtpCrbRequestUseTpm ((PTP_CRB_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r