TianoCore EDK2 master
Loading...
Searching...
No Matches
TisPc.c
Go to the documentation of this file.
1
9#include "CommonHeader.h"
10
19BOOLEAN
22 )
23{
24 UINT8 RegRead;
25
26 RegRead = MmioRead8 ((UINTN)&TisReg->Access);
27 return (BOOLEAN)(RegRead != (UINT8)-1);
28}
29
42EFIAPI
44 IN UINT8 *Register,
45 IN UINT8 BitSet,
46 IN UINT8 BitClear,
47 IN UINT32 TimeOut
48 )
49{
50 UINT8 RegRead;
51 UINT32 WaitTime;
52
53 for (WaitTime = 0; WaitTime < TimeOut; WaitTime += 30) {
54 RegRead = MmioRead8 ((UINTN)Register);
55 if (((RegRead & BitSet) == BitSet) && ((RegRead & BitClear) == 0)) {
56 return EFI_SUCCESS;
57 }
58
60 }
61
62 return EFI_TIMEOUT;
63}
64
77EFIAPI
80 OUT UINT16 *BurstCount
81 )
82{
83 UINT32 WaitTime;
84 UINT8 DataByte0;
85 UINT8 DataByte1;
86
87 if ((BurstCount == NULL) || (TisReg == NULL)) {
88 return EFI_INVALID_PARAMETER;
89 }
90
91 WaitTime = 0;
92 do {
93 //
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
96 //
97 DataByte0 = MmioRead8 ((UINTN)&TisReg->BurstCount);
98 DataByte1 = MmioRead8 ((UINTN)&TisReg->BurstCount + 1);
99 *BurstCount = (UINT16)((DataByte1 << 8) + DataByte0);
100 if (*BurstCount != 0) {
101 return EFI_SUCCESS;
102 }
103
104 MicroSecondDelay (30);
105 WaitTime += 30;
106 } while (WaitTime < TIS_TIMEOUT_D);
107
108 return EFI_TIMEOUT;
109}
110
122EFIAPI
125 )
126{
127 EFI_STATUS Status;
128
129 if (TisReg == NULL) {
130 return EFI_INVALID_PARAMETER;
131 }
132
133 MmioWrite8 ((UINTN)&TisReg->Status, TIS_PC_STS_READY);
134 Status = TisPcWaitRegisterBits (
135 &TisReg->Status,
137 0,
138 TIS_TIMEOUT_B
139 );
140 return Status;
141}
142
155EFIAPI
158 )
159{
160 EFI_STATUS Status;
161
162 if (TisReg == NULL) {
163 return EFI_INVALID_PARAMETER;
164 }
165
166 if (!TisPcPresenceCheck (TisReg)) {
167 return EFI_NOT_FOUND;
168 }
169
170 MmioWrite8 ((UINTN)&TisReg->Access, TIS_PC_ACC_RQUUSE);
171 //
172 // No locality set before, ACCESS_X.activeLocality MUST be valid within TIMEOUT_A
173 //
174 Status = TisPcWaitRegisterBits (
175 &TisReg->Access,
177 0,
178 TIS_TIMEOUT_A
179 );
180 return Status;
181}
UINT64 UINTN
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
UINT8 EFIAPI MmioRead8(IN UINTN Address)
Definition: IoLib.c:82
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
Definition: IoLib.c:126
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
BOOLEAN TisPcPresenceCheck(IN TIS_PC_REGISTERS_PTR TisReg)
Definition: TisPc.c:20
EFI_STATUS EFIAPI TisPcWaitRegisterBits(IN UINT8 *Register, IN UINT8 BitSet, IN UINT8 BitClear, IN UINT32 TimeOut)
Definition: TisPc.c:43
EFI_STATUS EFIAPI TisPcPrepareCommand(IN TIS_PC_REGISTERS_PTR TisReg)
Definition: TisPc.c:123
EFI_STATUS EFIAPI TisPcRequestUseTpm(IN TIS_PC_REGISTERS_PTR TisReg)
Definition: TisPc.c:156
EFI_STATUS EFIAPI TisPcReadBurstCount(IN TIS_PC_REGISTERS_PTR TisReg, OUT UINT16 *BurstCount)
Definition: TisPc.c:78
#define TIS_PC_VALID
Definition: TpmTis.h:110
#define TIS_PC_ACC_ACTIVE
Definition: TpmTis.h:114
#define TIS_PC_ACC_RQUUSE
Definition: TpmTis.h:133
#define TIS_PC_STS_READY
Definition: TpmTis.h:151
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112