22#define TIS_TIMEOUT_MAX (90000 * 1000)
27#define TPMCMDBUFLENGTH 0x500
45 return (BOOLEAN)(RegRead != (UINT8)-1);
70 for (WaitTime = 0; WaitTime < TimeOut; WaitTime += 30) {
72 if (((RegRead & BitSet) == BitSet) && ((RegRead & BitClear) == 0)) {
96 OUT UINT16 *BurstCount
103 if ((BurstCount ==
NULL) || (TisReg ==
NULL)) {
104 return EFI_INVALID_PARAMETER;
115 *BurstCount = (UINT16)((DataByte1 << 8) + DataByte0);
116 if (*BurstCount != 0) {
122 }
while (WaitTime < TIS_TIMEOUT_D);
144 if (TisReg ==
NULL) {
145 return EFI_INVALID_PARAMETER;
176 if (TisReg ==
NULL) {
177 return EFI_INVALID_PARAMETER;
181 return EFI_NOT_FOUND;
214 IN OUT UINT8 *BufferOut,
215 IN OUT UINT32 *SizeOut
228 DEBUG ((DEBUG_VERBOSE,
"Tpm2TisTpmCommand Send - "));
229 if (SizeIn > 0x100) {
235 for (Index = 0; Index < DebugSize; Index++) {
236 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferIn[Index]));
239 if (DebugSize != SizeIn) {
240 DEBUG ((DEBUG_VERBOSE,
"...... "));
241 for (Index = SizeIn - 0x20; Index < SizeIn; Index++) {
242 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferIn[Index]));
246 DEBUG ((DEBUG_VERBOSE,
"\n"));
251 if (EFI_ERROR (Status)) {
252 DEBUG ((DEBUG_ERROR,
"Tpm2 is not ready for command!\n"));
253 return EFI_DEVICE_ERROR;
260 while (Index < SizeIn) {
262 if (EFI_ERROR (Status)) {
263 Status = EFI_DEVICE_ERROR;
267 for ( ; BurstCount > 0 && Index < SizeIn; BurstCount--) {
282 if (EFI_ERROR (Status)) {
283 DEBUG ((DEBUG_ERROR,
"Tpm2 The send buffer too small!\n"));
284 Status = EFI_BUFFER_TOO_SMALL;
302 if (EFI_ERROR (Status)) {
307 DEBUG ((DEBUG_ERROR,
"Wait for Tpm2 response data time out. Trying to cancel the command!!\n"));
319 if (EFI_ERROR (Status)) {
324 Status = EFI_DEVICE_ERROR;
336 if (EFI_ERROR (Status)) {
337 Status = EFI_DEVICE_ERROR;
341 for ( ; BurstCount > 0; BurstCount--) {
351 DEBUG ((DEBUG_VERBOSE,
"Tpm2TisTpmCommand ReceiveHeader - "));
353 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferOut[Index]));
356 DEBUG ((DEBUG_VERBOSE,
"\n"));
361 CopyMem (&Data16, BufferOut,
sizeof (UINT16));
364 DEBUG ((DEBUG_ERROR,
"TPM2: TPM_ST_RSP error - %x\n", TPM_ST_RSP_COMMAND));
365 Status = EFI_UNSUPPORTED;
369 CopyMem (&Data32, (BufferOut + 2),
sizeof (UINT32));
371 if (*SizeOut < TpmOutSize) {
372 Status = EFI_BUFFER_TOO_SMALL;
376 *SizeOut = TpmOutSize;
380 while ( Index < TpmOutSize ) {
381 for ( ; BurstCount > 0; BurstCount--) {
384 if (Index == TpmOutSize) {
391 if (EFI_ERROR (Status)) {
392 Status = EFI_DEVICE_ERROR;
399 DEBUG ((DEBUG_VERBOSE,
"Tpm2TisTpmCommand Receive - "));
400 for (Index = 0; Index < TpmOutSize; Index++) {
401 DEBUG ((DEBUG_VERBOSE,
"%02x ", BufferOut[Index]));
404 DEBUG ((DEBUG_VERBOSE,
"\n"));
425 IN UINT32 InputParameterBlockSize,
426 IN UINT8 *InputParameterBlock,
427 IN OUT UINT32 *OutputParameterBlockSize,
428 IN UINT8 *OutputParameterBlock
434 InputParameterBlockSize,
435 OutputParameterBlock,
436 OutputParameterBlockSize
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 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)
EFI_STATUS TisPcReadBurstCount(IN TIS_PC_REGISTERS_PTR TisReg, OUT UINT16 *BurstCount)
EFI_STATUS EFIAPI DTpm2TisRequestUseTpm(VOID)
BOOLEAN TisPcPresenceCheck(IN TIS_PC_REGISTERS_PTR TisReg)
EFI_STATUS Tpm2TisTpmCommand(IN TIS_PC_REGISTERS_PTR TisReg, IN UINT8 *BufferIn, IN UINT32 SizeIn, IN OUT UINT8 *BufferOut, IN OUT UINT32 *SizeOut)
EFI_STATUS TisPcRequestUseTpm(IN TIS_PC_REGISTERS_PTR TisReg)
EFI_STATUS TisPcPrepareCommand(IN TIS_PC_REGISTERS_PTR TisReg)
EFI_STATUS EFIAPI DTpm2TisSubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
EFI_STATUS TisPcWaitRegisterBits(IN UINT8 *Register, IN UINT8 BitSet, IN UINT8 BitClear, IN UINT32 TimeOut)
#define TIS_PC_ACC_ACTIVE
#define TIS_PC_ACC_RQUUSE
#define TIS_PC_STS_EXPECT
#define TIS_PC_STS_CANCEL
VOID EFIAPI Exit(IN EFI_STATUS Status)