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)) {
59 MicroSecondDelay (30);
66 Get BurstCount by reading the burstCount field of a TIS register
67 in the time of default TIS_TIMEOUT_D.
69 @param[in] TisReg Pointer to TIS register.
70 @param[out] BurstCount Pointer to a buffer to store the got BurstCount.
72 @retval EFI_SUCCESS Get BurstCount.
73 @retval EFI_INVALID_PARAMETER TisReg is NULL or BurstCount is NULL.
74 @retval EFI_TIMEOUT BurstCount can't be got in time.
79 IN TIS_PC_REGISTERS_PTR TisReg
,
80 OUT UINT16
*BurstCount
87 if ((BurstCount
== NULL
) || (TisReg
== NULL
)) {
88 return EFI_INVALID_PARAMETER
;
94 // TIS_PC_REGISTERS_PTR->burstCount is UINT16, but it is not 2bytes aligned,
95 // so it needs to use MmioRead8 to read two times
97 DataByte0
= MmioRead8 ((UINTN
)&TisReg
->BurstCount
);
98 DataByte1
= MmioRead8 ((UINTN
)&TisReg
->BurstCount
+ 1);
99 *BurstCount
= (UINT16
)((DataByte1
<< 8) + DataByte0
);
100 if (*BurstCount
!= 0) {
104 MicroSecondDelay (30);
106 } while (WaitTime
< TIS_TIMEOUT_D
);
112 Set TPM chip to ready state by sending ready command TIS_PC_STS_READY
113 to Status Register in time.
115 @param[in] TisReg Pointer to TIS register.
117 @retval EFI_SUCCESS TPM chip enters into ready state.
118 @retval EFI_INVALID_PARAMETER TisReg is NULL.
119 @retval EFI_TIMEOUT TPM chip can't be set to ready state in time.
123 TisPcPrepareCommand (
124 IN TIS_PC_REGISTERS_PTR TisReg
129 if (TisReg
== NULL
) {
130 return EFI_INVALID_PARAMETER
;
133 MmioWrite8 ((UINTN
)&TisReg
->Status
, TIS_PC_STS_READY
);
134 Status
= TisPcWaitRegisterBits (
144 Get the control of TPM chip by sending requestUse command TIS_PC_ACC_RQUUSE
145 to ACCESS Register in the time of default TIS_TIMEOUT_A.
147 @param[in] TisReg Pointer to TIS register.
149 @retval EFI_SUCCESS Get the control of TPM chip.
150 @retval EFI_INVALID_PARAMETER TisReg is NULL.
151 @retval EFI_NOT_FOUND TPM chip doesn't exit.
152 @retval EFI_TIMEOUT Can't get the TPM control in time.
157 IN TIS_PC_REGISTERS_PTR TisReg
162 if (TisReg
== NULL
) {
163 return EFI_INVALID_PARAMETER
;
166 if (!TisPcPresenceCheck (TisReg
)) {
167 return EFI_NOT_FOUND
;
170 MmioWrite8 ((UINTN
)&TisReg
->Access
, TIS_PC_ACC_RQUUSE
);
172 // No locality set before, ACCESS_X.activeLocality MUST be valid within TIMEOUT_A
174 Status
= TisPcWaitRegisterBits (
176 (UINT8
)(TIS_PC_ACC_ACTIVE
|TIS_PC_VALID
),