2 Basic TIS (TPM Interface Specification) functions.
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "CommonHeader.h"
12 Check whether TPM chip exist.
14 @param[in] TisReg Pointer to TIS register.
16 @retval TRUE TPM chip exists.
17 @retval FALSE TPM chip is not found.
21 IN TIS_PC_REGISTERS_PTR TisReg
26 RegRead
= MmioRead8 ((UINTN
)&TisReg
->Access
);
27 return (BOOLEAN
)(RegRead
!= (UINT8
)-1);
31 Check whether the value of a TPM chip register satisfies the input BIT setting.
33 @param[in] Register Address port of register to be checked.
34 @param[in] BitSet Check these data bits are set.
35 @param[in] BitClear Check these data bits are clear.
36 @param[in] TimeOut The max wait time (unit MicroSecond) when checking register.
38 @retval EFI_SUCCESS The register satisfies the check bit.
39 @retval EFI_TIMEOUT The register can't run into the expected status in time.
43 TisPcWaitRegisterBits (
53 for (WaitTime
= 0; WaitTime
< TimeOut
; WaitTime
+= 30){
54 RegRead
= MmioRead8 ((UINTN
)Register
);
55 if ((RegRead
& BitSet
) == BitSet
&& (RegRead
& BitClear
) == 0)
57 MicroSecondDelay (30);
63 Get BurstCount by reading the burstCount field of a TIS regiger
64 in the time of default TIS_TIMEOUT_D.
66 @param[in] TisReg Pointer to TIS register.
67 @param[out] BurstCount Pointer to a buffer to store the got BurstCount.
69 @retval EFI_SUCCESS Get BurstCount.
70 @retval EFI_INVALID_PARAMETER TisReg is NULL or BurstCount is NULL.
71 @retval EFI_TIMEOUT BurstCount can't be got in time.
76 IN TIS_PC_REGISTERS_PTR TisReg
,
77 OUT UINT16
*BurstCount
84 if (BurstCount
== NULL
|| TisReg
== NULL
) {
85 return EFI_INVALID_PARAMETER
;
91 // TIS_PC_REGISTERS_PTR->burstCount is UINT16, but it is not 2bytes aligned,
92 // so it needs to use MmioRead8 to read two times
94 DataByte0
= MmioRead8 ((UINTN
)&TisReg
->BurstCount
);
95 DataByte1
= MmioRead8 ((UINTN
)&TisReg
->BurstCount
+ 1);
96 *BurstCount
= (UINT16
)((DataByte1
<< 8) + DataByte0
);
97 if (*BurstCount
!= 0) {
100 MicroSecondDelay (30);
102 } while (WaitTime
< TIS_TIMEOUT_D
);
108 Set TPM chip to ready state by sending ready command TIS_PC_STS_READY
109 to Status Register in time.
111 @param[in] TisReg Pointer to TIS register.
113 @retval EFI_SUCCESS TPM chip enters into ready state.
114 @retval EFI_INVALID_PARAMETER TisReg is NULL.
115 @retval EFI_TIMEOUT TPM chip can't be set to ready state in time.
119 TisPcPrepareCommand (
120 IN TIS_PC_REGISTERS_PTR TisReg
125 if (TisReg
== NULL
) {
126 return EFI_INVALID_PARAMETER
;
129 MmioWrite8((UINTN
)&TisReg
->Status
, TIS_PC_STS_READY
);
130 Status
= TisPcWaitRegisterBits (
140 Get the control of TPM chip by sending requestUse command TIS_PC_ACC_RQUUSE
141 to ACCESS Register in the time of default TIS_TIMEOUT_A.
143 @param[in] TisReg Pointer to TIS register.
145 @retval EFI_SUCCESS Get the control of TPM chip.
146 @retval EFI_INVALID_PARAMETER TisReg is NULL.
147 @retval EFI_NOT_FOUND TPM chip doesn't exit.
148 @retval EFI_TIMEOUT Can't get the TPM control in time.
153 IN TIS_PC_REGISTERS_PTR TisReg
158 if (TisReg
== NULL
) {
159 return EFI_INVALID_PARAMETER
;
162 if (!TisPcPresenceCheck (TisReg
)) {
163 return EFI_NOT_FOUND
;
166 MmioWrite8((UINTN
)&TisReg
->Access
, TIS_PC_ACC_RQUUSE
);
168 // No locality set before, ACCESS_X.activeLocality MUST be valid within TIMEOUT_A
170 Status
= TisPcWaitRegisterBits (
172 (UINT8
)(TIS_PC_ACC_ACTIVE
|TIS_PC_VALID
),