29#define PTP_TIMEOUT_MAX (90000 * 1000)
34#define TPMCMDBUFLENGTH 0x500
40#define RETRY_CNT_MAX 3
58 if (RegRead == 0xFF) {
90 for (WaitTime = 0; WaitTime < TimeOut; WaitTime += 30) {
92 if (((RegRead & BitSet) == BitSet) && ((RegRead & BitClear) == 0)) {
120 return EFI_NOT_FOUND;
125 &CrbReg->LocalityStatus,
153 IN OUT UINT8 *BufferOut,
154 IN OUT UINT32 *SizeOut
167 DEBUG ((DEBUG_VERBOSE,
"PtpCrbTpmCommand Send - "));
168 if (SizeIn > 0x100) {
174 for (Index = 0; Index < DebugSize; Index++) {
175 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferIn[Index]));
178 if (DebugSize != SizeIn) {
179 DEBUG ((DEBUG_VERBOSE,
"...... "));
180 for (Index = SizeIn - 0x20; Index < SizeIn; Index++) {
181 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferIn[Index]));
185 DEBUG ((DEBUG_VERBOSE,
"\n"));
197 &CrbReg->CrbControlStatus,
202 if (EFI_ERROR (Status)) {
204 if (RetryCnt < RETRY_CNT_MAX) {
211 Status = EFI_DEVICE_ERROR;
225 &CrbReg->CrbControlRequest,
230 if (EFI_ERROR (Status)) {
232 if (RetryCnt < RETRY_CNT_MAX) {
236 Status = EFI_DEVICE_ERROR;
242 &CrbReg->CrbControlStatus,
247 if (EFI_ERROR (Status)) {
249 if (RetryCnt < RETRY_CNT_MAX) {
253 Status = EFI_DEVICE_ERROR;
267 for (Index = 0; Index < SizeIn; Index++) {
273 MmioWrite32 ((
UINTN)&CrbReg->CrbControlCommandSize, sizeof (CrbReg->CrbDataBuffer));
276 MmioWrite32 ((
UINTN)&CrbReg->CrbControlResponseSize, sizeof (CrbReg->CrbDataBuffer));
285 &CrbReg->CrbControlStart,
290 if (EFI_ERROR (Status)) {
297 &CrbReg->CrbControlStart,
304 if (EFI_ERROR (Status)) {
308 Status = EFI_DEVICE_ERROR;
324 BufferOut[Index] =
MmioRead8 ((
UINTN)&CrbReg->CrbDataBuffer[Index]);
328 DEBUG ((DEBUG_VERBOSE,
"PtpCrbTpmCommand ReceiveHeader - "));
330 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferOut[Index]));
333 DEBUG ((DEBUG_VERBOSE,
"\n"));
338 CopyMem (&Data16, BufferOut,
sizeof (UINT16));
341 DEBUG ((DEBUG_ERROR,
"TPM2: TPM_ST_RSP error - %x\n", TPM_ST_RSP_COMMAND));
342 Status = EFI_UNSUPPORTED;
346 CopyMem (&Data32, (BufferOut + 2),
sizeof (UINT32));
348 if (*SizeOut < TpmOutSize) {
352 Status = EFI_BUFFER_TOO_SMALL;
356 *SizeOut = TpmOutSize;
361 BufferOut[Index] =
MmioRead8 ((
UINTN)&CrbReg->CrbDataBuffer[Index]);
365 DEBUG ((DEBUG_VERBOSE,
"PtpCrbTpmCommand Receive - "));
366 for (Index = 0; Index < TpmOutSize; Index++) {
367 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferOut[Index]));
370 DEBUG ((DEBUG_VERBOSE,
"\n"));
407 IN OUT UINT8 *BufferOut,
408 IN OUT UINT32 *SizeOut
434TPM2_PTP_INTERFACE_TYPE
443 return Tpm2PtpInterfaceMax;
452 if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) &&
453 (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&
454 (InterfaceId.Bits.CapCRB != 0))
456 return Tpm2PtpInterfaceCrb;
461 (InterfaceId.Bits.CapFIFO != 0) &&
462 (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP))
464 return Tpm2PtpInterfaceFifo;
467 if (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_TIS) {
468 return Tpm2PtpInterfaceTis;
471 return Tpm2PtpInterfaceMax;
493 return (UINT8)(InterfaceId.Bits.CapCRBIdleBypass);
512 TPM2_PTP_INTERFACE_TYPE PtpInterface;
525 DEBUG ((DEBUG_INFO,
"InterfaceId - 0x%08x\n", InterfaceId.Uint32));
526 DEBUG ((DEBUG_INFO,
" InterfaceType - 0x%02x\n", InterfaceId.Bits.InterfaceType));
527 if (InterfaceId.Bits.InterfaceType != PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_TIS) {
528 DEBUG ((DEBUG_INFO,
" InterfaceVersion - 0x%02x\n", InterfaceId.Bits.InterfaceVersion));
529 DEBUG ((DEBUG_INFO,
" CapFIFO - 0x%x\n", InterfaceId.Bits.CapFIFO));
530 DEBUG ((DEBUG_INFO,
" CapCRB - 0x%x\n", InterfaceId.Bits.CapCRB));
536 DEBUG ((DEBUG_INFO,
"InterfaceCapability - 0x%08x\n", InterfaceCapability.Uint32));
537 if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_TIS) ||
540 DEBUG ((DEBUG_INFO,
" InterfaceVersion - 0x%x\n", InterfaceCapability.Bits.InterfaceVersion));
546 DEBUG ((DEBUG_INFO,
"StatusEx - 0x%02x\n", StatusEx));
547 if (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP) {
555 DEBUG ((DEBUG_INFO,
"PtpInterface - %x\n", PtpInterface));
556 switch (PtpInterface) {
557 case Tpm2PtpInterfaceCrb:
560 Rid = (UINT8)InterfaceId.Bits.Rid;
562 case Tpm2PtpInterfaceFifo:
563 case Tpm2PtpInterfaceTis:
572 DEBUG ((DEBUG_INFO,
"VID - 0x%04x\n", Vid));
573 DEBUG ((DEBUG_INFO,
"DID - 0x%04x\n", Did));
574 DEBUG ((DEBUG_INFO,
"RID - 0x%02x\n", Rid));
592 IN UINT32 InputParameterBlockSize,
593 IN UINT8 *InputParameterBlock,
594 IN OUT UINT32 *OutputParameterBlockSize,
595 IN UINT8 *OutputParameterBlock
598 TPM2_PTP_INTERFACE_TYPE PtpInterface;
601 switch (PtpInterface) {
602 case Tpm2PtpInterfaceCrb:
606 InputParameterBlockSize,
607 OutputParameterBlock,
608 OutputParameterBlockSize
610 case Tpm2PtpInterfaceFifo:
611 case Tpm2PtpInterfaceTis:
615 InputParameterBlockSize,
616 OutputParameterBlock,
617 OutputParameterBlockSize
620 return EFI_NOT_FOUND;
637 TPM2_PTP_INTERFACE_TYPE PtpInterface;
640 switch (PtpInterface) {
641 case Tpm2PtpInterfaceCrb:
643 case Tpm2PtpInterfaceFifo:
644 case Tpm2PtpInterfaceTis:
647 return EFI_NOT_FOUND;
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINT64 EFIAPI MmioWrite64(IN UINTN Address, IN UINT64 Value)
UINT16 EFIAPI MmioRead16(IN UINTN Address)
UINT8 EFIAPI MmioRead8(IN UINTN Address)
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
#define PcdGet64(TokenName)
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
TPM2_PTP_INTERFACE_TYPE GetCachedPtpInterface(VOID)
UINT8 GetCachedIdleByPass(VOID)
UINT8 Tpm2GetIdleByPass(IN VOID *Register)
EFI_STATUS Tpm2TisTpmCommand(IN TIS_PC_REGISTERS_PTR TisReg, IN UINT8 *BufferIn, IN UINT32 SizeIn, IN OUT UINT8 *BufferOut, IN OUT UINT32 *SizeOut)
TPM2_PTP_INTERFACE_TYPE Tpm2GetPtpInterface(IN VOID *Register)
EFI_STATUS EFIAPI DTpm2SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
EFI_STATUS TisPcRequestUseTpm(IN TIS_PC_REGISTERS_PTR TisReg)
VOID DumpPtpInfo(IN VOID *Register)
BOOLEAN Tpm2IsPtpPresence(IN VOID *Reg)
EFI_STATUS EFIAPI DTpm2RequestUseTpm(VOID)
EFI_STATUS PtpCrbWaitRegisterBits(IN UINT32 *Register, IN UINT32 BitSet, IN UINT32 BitClear, IN UINT32 TimeOut)
EFI_STATUS PtpCrbRequestUseTpm(IN PTP_CRB_REGISTERS_PTR CrbReg)
EFI_STATUS PtpCrbTpmCommand(IN PTP_CRB_REGISTERS_PTR CrbReg, IN UINT8 *BufferIn, IN UINT32 SizeIn, IN OUT UINT8 *BufferOut, IN OUT UINT32 *SizeOut)
#define PTP_CRB_CONTROL_START
#define PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE
#define PTP_CRB_LOCALITY_STATUS_GRANTED
#define PTP_CRB_CONTROL_CANCEL
#define PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO
#define PTP_CRB_CONTROL_AREA_REQUEST_COMMAND_READY
#define PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
#define PTP_CRB_LOCALITY_CONTROL_REQUEST_ACCESS
#define PTP_CRB_CONTROL_AREA_REQUEST_GO_IDLE
#define PTP_FIFO_STS_EX_TPM_FAMILY