33#define TPMCMDBUFLENGTH 1024
51 return (BOOLEAN)(RegRead != (UINT8)-1);
70 return PtpInterfaceMax;
79 if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) &&
80 (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&
81 (InterfaceId.Bits.CapCRB != 0))
83 return PtpInterfaceCrb;
88 (InterfaceId.Bits.CapFIFO != 0) &&
89 (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP))
91 return PtpInterfaceFifo;
94 if (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_TIS) {
95 return PtpInterfaceTis;
98 return PtpInterfaceMax;
123 for (WaitTime = 0; WaitTime < TimeOut; WaitTime += 30) {
125 if (((RegRead & BitSet) == BitSet) && ((RegRead & BitClear) == 0)) {
149 OUT UINT16 *BurstCount
156 if ((BurstCount ==
NULL) || (TisReg ==
NULL)) {
157 return EFI_INVALID_PARAMETER;
168 *BurstCount = (UINT16)((DataByte1 << 8) + DataByte0);
169 if (*BurstCount != 0) {
175 }
while (WaitTime < TIS_TIMEOUT_D);
197 if (TisReg ==
NULL) {
198 return EFI_INVALID_PARAMETER;
229 if (TisReg ==
NULL) {
230 return EFI_INVALID_PARAMETER;
234 return EFI_NOT_FOUND;
267 IN OUT UINT8 *BufferOut,
268 IN OUT UINT32 *SizeOut
282 DEBUG ((DEBUG_VERBOSE,
"Tpm12TisTpmCommand Send - "));
283 if (SizeIn > 0x100) {
289 for (Index = 0; Index < DebugSize; Index++) {
290 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferIn[Index]));
293 if (DebugSize != SizeIn) {
294 DEBUG ((DEBUG_VERBOSE,
"...... "));
295 for (Index = SizeIn - 0x20; Index < SizeIn; Index++) {
296 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferIn[Index]));
300 DEBUG ((DEBUG_VERBOSE,
"\n"));
305 if (EFI_ERROR (Status)) {
306 DEBUG ((DEBUG_ERROR,
"Tpm12 is not ready for command!\n"));
307 return EFI_DEVICE_ERROR;
314 while (Index < SizeIn) {
316 if (EFI_ERROR (Status)) {
317 Status = EFI_DEVICE_ERROR;
321 for ( ; BurstCount > 0 && Index < SizeIn; BurstCount--) {
336 if (EFI_ERROR (Status)) {
337 DEBUG ((DEBUG_ERROR,
"Tpm12 The send buffer too small!\n"));
338 Status = EFI_BUFFER_TOO_SMALL;
352 if (EFI_ERROR (Status)) {
353 DEBUG ((DEBUG_ERROR,
"Wait for Tpm12 response data time out!!\n"));
354 Status = EFI_DEVICE_ERROR;
365 if (EFI_ERROR (Status)) {
366 Status = EFI_DEVICE_ERROR;
370 for ( ; BurstCount > 0; BurstCount--) {
380 DEBUG ((DEBUG_VERBOSE,
"Tpm12TisTpmCommand ReceiveHeader - "));
382 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferOut[Index]));
385 DEBUG ((DEBUG_VERBOSE,
"\n"));
390 CopyMem (&Data16, BufferOut,
sizeof (UINT16));
392 if ((RspTag != TPM_TAG_RSP_COMMAND) && (RspTag != TPM_TAG_RSP_AUTH1_COMMAND) && (RspTag != TPM_TAG_RSP_AUTH2_COMMAND)) {
393 DEBUG ((DEBUG_ERROR,
"TPM12: Response tag error - current tag value is %x\n", RspTag));
394 Status = EFI_UNSUPPORTED;
398 CopyMem (&Data32, (BufferOut + 2),
sizeof (UINT32));
400 if (*SizeOut < TpmOutSize) {
401 Status = EFI_BUFFER_TOO_SMALL;
405 *SizeOut = TpmOutSize;
409 while ( Index < TpmOutSize ) {
410 for ( ; BurstCount > 0; BurstCount--) {
413 if (Index == TpmOutSize) {
420 if (EFI_ERROR (Status)) {
421 Status = EFI_DEVICE_ERROR;
428 DEBUG ((DEBUG_VERBOSE,
"Tpm12TisTpmCommand Receive - "));
429 for (Index = 0; Index < TpmOutSize; Index++) {
430 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferOut[Index]));
433 DEBUG ((DEBUG_VERBOSE,
"\n"));
454 IN UINT32 InputParameterBlockSize,
455 IN UINT8 *InputParameterBlock,
456 IN OUT UINT32 *OutputParameterBlockSize,
457 IN UINT8 *OutputParameterBlock
460 PTP_INTERFACE_TYPE PtpInterface;
466 switch (PtpInterface) {
467 case PtpInterfaceFifo:
468 case PtpInterfaceTis:
472 InputParameterBlockSize,
473 OutputParameterBlock,
474 OutputParameterBlockSize
476 case PtpInterfaceCrb:
481 return EFI_DEVICE_ERROR;
507 for (WaitTime = 0; WaitTime < TimeOut; WaitTime += 30) {
509 if (((RegRead & BitSet) == BitSet) && ((RegRead & BitClear) == 0)) {
538 &CrbReg->LocalityStatus,
559 PTP_INTERFACE_TYPE PtpInterface;
566 switch (PtpInterface) {
567 case PtpInterfaceCrb:
569 case PtpInterfaceFifo:
570 case PtpInterfaceTis:
573 return EFI_NOT_FOUND;
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
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)
struct tdTPM_RSP_COMMAND_HDR TPM_RSP_COMMAND_HDR
EFI_STATUS Tpm12TisPcWaitRegisterBits(IN UINT8 *Register, IN UINT8 BitSet, IN UINT8 BitClear, IN UINT32 TimeOut)
EFI_STATUS EFIAPI Tpm12RequestUseTpm(VOID)
EFI_STATUS Tpm12TisTpmCommand(IN TIS_PC_REGISTERS_PTR TisReg, IN UINT8 *BufferIn, IN UINT32 SizeIn, IN OUT UINT8 *BufferOut, IN OUT UINT32 *SizeOut)
EFI_STATUS EFIAPI Tpm12SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
BOOLEAN Tpm12TisPcPresenceCheck(IN TIS_PC_REGISTERS_PTR TisReg)
EFI_STATUS Tpm12TisPcPrepareCommand(IN TIS_PC_REGISTERS_PTR TisReg)
PTP_INTERFACE_TYPE Tpm12GetPtpInterface(IN VOID *Register)
EFI_STATUS Tpm12TisPcReadBurstCount(IN TIS_PC_REGISTERS_PTR TisReg, OUT UINT16 *BurstCount)
EFI_STATUS Tpm12TisPcRequestUseTpm(IN TIS_PC_REGISTERS_PTR TisReg)
EFI_STATUS Tpm12PtpCrbRequestUseTpm(IN PTP_CRB_REGISTERS_PTR CrbReg)
EFI_STATUS Tpm12PtpCrbWaitRegisterBits(IN UINT32 *Register, IN UINT32 BitSet, IN UINT32 BitClear, IN UINT32 TimeOut)
#define PTP_CRB_LOCALITY_STATUS_GRANTED
#define PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO
#define PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
#define PTP_CRB_LOCALITY_CONTROL_REQUEST_ACCESS
#define TIS_PC_ACC_ACTIVE
#define TIS_PC_ACC_RQUUSE
#define TIS_PC_STS_EXPECT
VOID EFIAPI Exit(IN EFI_STATUS Status)