]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
SecurityPkg: TPM must go to Idle state on CRB command completion
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2Ptp.c
1 /** @file
2 PTP (Platform TPM Profile) CRB (Command Response Buffer) interface used by dTPM2.0 library.
3
4 Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>
5 Copyright (c), Microsoft Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <IndustryStandard/Tpm20.h>
11
12 #include <Library/BaseLib.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/IoLib.h>
15 #include <Library/TimerLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/Tpm2DeviceLib.h>
18 #include <Library/PcdLib.h>
19
20 #include <IndustryStandard/TpmPtp.h>
21 #include <IndustryStandard/TpmTis.h>
22
23 #include "Tpm2DeviceLibDTpm.h"
24
25 //
26 // Execution of the command may take from several seconds to minutes for certain
27 // commands, such as key generation.
28 //
29 #define PTP_TIMEOUT_MAX (90000 * 1000) // 90s
30
31 //
32 // Max TPM command/response length
33 //
34 #define TPMCMDBUFLENGTH 0x500
35
36 /**
37 Check whether TPM PTP register exist.
38
39 @param[in] Reg Pointer to PTP register.
40
41 @retval TRUE TPM PTP exists.
42 @retval FALSE TPM PTP is not found.
43 **/
44 BOOLEAN
45 Tpm2IsPtpPresence (
46 IN VOID *Reg
47 )
48 {
49 UINT8 RegRead;
50
51 RegRead = MmioRead8 ((UINTN)Reg);
52 if (RegRead == 0xFF) {
53 //
54 // No TPM chip
55 //
56 return FALSE;
57 }
58
59 return TRUE;
60 }
61
62 /**
63 Check whether the value of a TPM chip register satisfies the input BIT setting.
64
65 @param[in] Register Address port of register to be checked.
66 @param[in] BitSet Check these data bits are set.
67 @param[in] BitClear Check these data bits are clear.
68 @param[in] TimeOut The max wait time (unit MicroSecond) when checking register.
69
70 @retval EFI_SUCCESS The register satisfies the check bit.
71 @retval EFI_TIMEOUT The register can't run into the expected status in time.
72 **/
73 EFI_STATUS
74 PtpCrbWaitRegisterBits (
75 IN UINT32 *Register,
76 IN UINT32 BitSet,
77 IN UINT32 BitClear,
78 IN UINT32 TimeOut
79 )
80 {
81 UINT32 RegRead;
82 UINT32 WaitTime;
83
84 for (WaitTime = 0; WaitTime < TimeOut; WaitTime += 30) {
85 RegRead = MmioRead32 ((UINTN)Register);
86 if (((RegRead & BitSet) == BitSet) && ((RegRead & BitClear) == 0)) {
87 return EFI_SUCCESS;
88 }
89
90 MicroSecondDelay (30);
91 }
92
93 return EFI_TIMEOUT;
94 }
95
96 /**
97 Get the control of TPM chip.
98
99 @param[in] CrbReg Pointer to CRB register.
100
101 @retval EFI_SUCCESS Get the control of TPM chip.
102 @retval EFI_INVALID_PARAMETER CrbReg is NULL.
103 @retval EFI_NOT_FOUND TPM chip doesn't exit.
104 @retval EFI_TIMEOUT Can't get the TPM control in time.
105 **/
106 EFI_STATUS
107 PtpCrbRequestUseTpm (
108 IN PTP_CRB_REGISTERS_PTR CrbReg
109 )
110 {
111 EFI_STATUS Status;
112
113 if (!Tpm2IsPtpPresence (CrbReg)) {
114 return EFI_NOT_FOUND;
115 }
116
117 MmioWrite32 ((UINTN)&CrbReg->LocalityControl, PTP_CRB_LOCALITY_CONTROL_REQUEST_ACCESS);
118 Status = PtpCrbWaitRegisterBits (
119 &CrbReg->LocalityStatus,
120 PTP_CRB_LOCALITY_STATUS_GRANTED,
121 0,
122 PTP_TIMEOUT_A
123 );
124 return Status;
125 }
126
127 /**
128 Send a command to TPM for execution and return response data.
129
130 @param[in] CrbReg TPM register space base address.
131 @param[in] BufferIn Buffer for command data.
132 @param[in] SizeIn Size of command data.
133 @param[in, out] BufferOut Buffer for response data.
134 @param[in, out] SizeOut Size of response data.
135
136 @retval EFI_SUCCESS Operation completed successfully.
137 @retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
138 @retval EFI_DEVICE_ERROR Unexpected device behavior.
139 @retval EFI_UNSUPPORTED Unsupported TPM version
140
141 **/
142 EFI_STATUS
143 PtpCrbTpmCommand (
144 IN PTP_CRB_REGISTERS_PTR CrbReg,
145 IN UINT8 *BufferIn,
146 IN UINT32 SizeIn,
147 IN OUT UINT8 *BufferOut,
148 IN OUT UINT32 *SizeOut
149 )
150 {
151 EFI_STATUS Status;
152 UINT32 Index;
153 UINT32 TpmOutSize;
154 UINT16 Data16;
155 UINT32 Data32;
156
157 DEBUG_CODE_BEGIN ();
158 UINTN DebugSize;
159
160 DEBUG ((DEBUG_VERBOSE, "PtpCrbTpmCommand Send - "));
161 if (SizeIn > 0x100) {
162 DebugSize = 0x40;
163 } else {
164 DebugSize = SizeIn;
165 }
166
167 for (Index = 0; Index < DebugSize; Index++) {
168 DEBUG ((DEBUG_VERBOSE, "%02x ", BufferIn[Index]));
169 }
170
171 if (DebugSize != SizeIn) {
172 DEBUG ((DEBUG_VERBOSE, "...... "));
173 for (Index = SizeIn - 0x20; Index < SizeIn; Index++) {
174 DEBUG ((DEBUG_VERBOSE, "%02x ", BufferIn[Index]));
175 }
176 }
177
178 DEBUG ((DEBUG_VERBOSE, "\n"));
179 DEBUG_CODE_END ();
180 TpmOutSize = 0;
181
182 //
183 // STEP 0:
184 // if CapCRbIdelByPass == 0, enforce Idle state before sending command
185 //
186 if ((GetCachedIdleByPass () == 0) && ((MmioRead32 ((UINTN)&CrbReg->CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0)) {
187 Status = PtpCrbWaitRegisterBits (
188 &CrbReg->CrbControlStatus,
189 PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
190 0,
191 PTP_TIMEOUT_C
192 );
193 if (EFI_ERROR (Status)) {
194 //
195 // Try to goIdle to recover TPM
196 //
197 Status = EFI_DEVICE_ERROR;
198 goto GoIdle_Exit;
199 }
200 }
201
202 //
203 // STEP 1:
204 // Ready is any time the TPM is ready to receive a command, following a write
205 // of 1 by software to Request.cmdReady, as indicated by the Status field
206 // being cleared to 0.
207 //
208 MmioWrite32 ((UINTN)&CrbReg->CrbControlRequest, PTP_CRB_CONTROL_AREA_REQUEST_COMMAND_READY);
209 Status = PtpCrbWaitRegisterBits (
210 &CrbReg->CrbControlRequest,
211 0,
212 PTP_CRB_CONTROL_AREA_REQUEST_COMMAND_READY,
213 PTP_TIMEOUT_C
214 );
215 if (EFI_ERROR (Status)) {
216 Status = EFI_DEVICE_ERROR;
217 goto GoIdle_Exit;
218 }
219
220 Status = PtpCrbWaitRegisterBits (
221 &CrbReg->CrbControlStatus,
222 0,
223 PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
224 PTP_TIMEOUT_C
225 );
226 if (EFI_ERROR (Status)) {
227 Status = EFI_DEVICE_ERROR;
228 goto GoIdle_Exit;
229 }
230
231 //
232 // STEP 2:
233 // Command Reception occurs following a Ready state between the write of the
234 // first byte of a command to the Command Buffer and the receipt of a write
235 // of 1 to Start.
236 //
237 for (Index = 0; Index < SizeIn; Index++) {
238 MmioWrite8 ((UINTN)&CrbReg->CrbDataBuffer[Index], BufferIn[Index]);
239 }
240
241 MmioWrite32 ((UINTN)&CrbReg->CrbControlCommandAddressHigh, (UINT32)RShiftU64 ((UINTN)CrbReg->CrbDataBuffer, 32));
242 MmioWrite32 ((UINTN)&CrbReg->CrbControlCommandAddressLow, (UINT32)(UINTN)CrbReg->CrbDataBuffer);
243 MmioWrite32 ((UINTN)&CrbReg->CrbControlCommandSize, sizeof (CrbReg->CrbDataBuffer));
244
245 MmioWrite64 ((UINTN)&CrbReg->CrbControlResponseAddrss, (UINT32)(UINTN)CrbReg->CrbDataBuffer);
246 MmioWrite32 ((UINTN)&CrbReg->CrbControlResponseSize, sizeof (CrbReg->CrbDataBuffer));
247
248 //
249 // STEP 3:
250 // Command Execution occurs after receipt of a 1 to Start and the TPM
251 // clearing Start to 0.
252 //
253 MmioWrite32 ((UINTN)&CrbReg->CrbControlStart, PTP_CRB_CONTROL_START);
254 Status = PtpCrbWaitRegisterBits (
255 &CrbReg->CrbControlStart,
256 0,
257 PTP_CRB_CONTROL_START,
258 PTP_TIMEOUT_MAX
259 );
260 if (EFI_ERROR (Status)) {
261 //
262 // Command Completion check timeout. Cancel the currently executing command by writing TPM_CRB_CTRL_CANCEL,
263 // Expect TPM_RC_CANCELLED or successfully completed response.
264 //
265 MmioWrite32 ((UINTN)&CrbReg->CrbControlCancel, PTP_CRB_CONTROL_CANCEL);
266 Status = PtpCrbWaitRegisterBits (
267 &CrbReg->CrbControlStart,
268 0,
269 PTP_CRB_CONTROL_START,
270 PTP_TIMEOUT_B
271 );
272 MmioWrite32 ((UINTN)&CrbReg->CrbControlCancel, 0);
273
274 if (EFI_ERROR (Status)) {
275 //
276 // Still in Command Execution state. Try to goIdle, the behavior is agnostic.
277 //
278 Status = EFI_DEVICE_ERROR;
279 goto GoIdle_Exit;
280 }
281 }
282
283 //
284 // STEP 4:
285 // Command Completion occurs after completion of a command (indicated by the
286 // TPM clearing TPM_CRB_CTRL_Start_x to 0) and before a write of a 1 by the
287 // software to Request.goIdle.
288 //
289
290 //
291 // Get response data header
292 //
293 for (Index = 0; Index < sizeof (TPM2_RESPONSE_HEADER); Index++) {
294 BufferOut[Index] = MmioRead8 ((UINTN)&CrbReg->CrbDataBuffer[Index]);
295 }
296
297 DEBUG_CODE_BEGIN ();
298 DEBUG ((DEBUG_VERBOSE, "PtpCrbTpmCommand ReceiveHeader - "));
299 for (Index = 0; Index < sizeof (TPM2_RESPONSE_HEADER); Index++) {
300 DEBUG ((DEBUG_VERBOSE, "%02x ", BufferOut[Index]));
301 }
302
303 DEBUG ((DEBUG_VERBOSE, "\n"));
304 DEBUG_CODE_END ();
305 //
306 // Check the response data header (tag, parasize and returncode)
307 //
308 CopyMem (&Data16, BufferOut, sizeof (UINT16));
309 // TPM2 should not use this RSP_COMMAND
310 if (SwapBytes16 (Data16) == TPM_ST_RSP_COMMAND) {
311 DEBUG ((DEBUG_ERROR, "TPM2: TPM_ST_RSP error - %x\n", TPM_ST_RSP_COMMAND));
312 Status = EFI_UNSUPPORTED;
313 goto GoIdle_Exit;
314 }
315
316 CopyMem (&Data32, (BufferOut + 2), sizeof (UINT32));
317 TpmOutSize = SwapBytes32 (Data32);
318 if (*SizeOut < TpmOutSize) {
319 //
320 // Command completed, but buffer is not enough
321 //
322 Status = EFI_BUFFER_TOO_SMALL;
323 goto GoIdle_Exit;
324 }
325
326 *SizeOut = TpmOutSize;
327 //
328 // Continue reading the remaining data
329 //
330 for (Index = sizeof (TPM2_RESPONSE_HEADER); Index < TpmOutSize; Index++) {
331 BufferOut[Index] = MmioRead8 ((UINTN)&CrbReg->CrbDataBuffer[Index]);
332 }
333
334 DEBUG_CODE_BEGIN ();
335 DEBUG ((DEBUG_VERBOSE, "PtpCrbTpmCommand Receive - "));
336 for (Index = 0; Index < TpmOutSize; Index++) {
337 DEBUG ((DEBUG_VERBOSE, "%02x ", BufferOut[Index]));
338 }
339
340 DEBUG ((DEBUG_VERBOSE, "\n"));
341 DEBUG_CODE_END ();
342
343 //
344 // Do not wait for state transition for TIMEOUT_C
345 // This function will try to wait 2 TIMEOUT_C at the beginning in next call.
346 //
347 GoIdle_Exit:
348
349 //
350 // Return to Idle state by setting TPM_CRB_CTRL_STS_x.Status.goIdle to 1.
351 //
352 MmioWrite32 ((UINTN)&CrbReg->CrbControlRequest, PTP_CRB_CONTROL_AREA_REQUEST_GO_IDLE);
353
354 //
355 // Only enforce Idle state transition if execution fails when CRBIdleBypass==1
356 // Leave regular Idle delay at the beginning of next command execution
357 //
358 if (GetCachedIdleByPass () == 1) {
359 Status = PtpCrbWaitRegisterBits (
360 &CrbReg->CrbControlStatus,
361 PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
362 0,
363 PTP_TIMEOUT_C
364 );
365 }
366
367 return Status;
368 }
369
370 /**
371 Send a command to TPM for execution and return response data.
372
373 @param[in] TisReg TPM register space base address.
374 @param[in] BufferIn Buffer for command data.
375 @param[in] SizeIn Size of command data.
376 @param[in, out] BufferOut Buffer for response data.
377 @param[in, out] SizeOut Size of response data.
378
379 @retval EFI_SUCCESS Operation completed successfully.
380 @retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
381 @retval EFI_DEVICE_ERROR Unexpected device behavior.
382 @retval EFI_UNSUPPORTED Unsupported TPM version
383
384 **/
385 EFI_STATUS
386 Tpm2TisTpmCommand (
387 IN TIS_PC_REGISTERS_PTR TisReg,
388 IN UINT8 *BufferIn,
389 IN UINT32 SizeIn,
390 IN OUT UINT8 *BufferOut,
391 IN OUT UINT32 *SizeOut
392 );
393
394 /**
395 Get the control of TPM chip by sending requestUse command TIS_PC_ACC_RQUUSE
396 to ACCESS Register in the time of default TIS_TIMEOUT_A.
397
398 @param[in] TisReg Pointer to TIS register.
399
400 @retval EFI_SUCCESS Get the control of TPM chip.
401 @retval EFI_INVALID_PARAMETER TisReg is NULL.
402 @retval EFI_NOT_FOUND TPM chip doesn't exit.
403 @retval EFI_TIMEOUT Can't get the TPM control in time.
404 **/
405 EFI_STATUS
406 TisPcRequestUseTpm (
407 IN TIS_PC_REGISTERS_PTR TisReg
408 );
409
410 /**
411 Return PTP interface type.
412
413 @param[in] Register Pointer to PTP register.
414
415 @return PTP interface type.
416 **/
417 TPM2_PTP_INTERFACE_TYPE
418 Tpm2GetPtpInterface (
419 IN VOID *Register
420 )
421 {
422 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;
423 PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability;
424
425 if (!Tpm2IsPtpPresence (Register)) {
426 return Tpm2PtpInterfaceMax;
427 }
428
429 //
430 // Check interface id
431 //
432 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);
433 InterfaceCapability.Uint32 = MmioRead32 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->InterfaceCapability);
434
435 if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) &&
436 (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB) &&
437 (InterfaceId.Bits.CapCRB != 0))
438 {
439 return Tpm2PtpInterfaceCrb;
440 }
441
442 if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO) &&
443 (InterfaceId.Bits.InterfaceVersion == PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO) &&
444 (InterfaceId.Bits.CapFIFO != 0) &&
445 (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP))
446 {
447 return Tpm2PtpInterfaceFifo;
448 }
449
450 return Tpm2PtpInterfaceTis;
451 }
452
453 /**
454 Return PTP CRB interface IdleByPass state.
455
456 @param[in] Register Pointer to PTP register.
457
458 @return PTP CRB interface IdleByPass state.
459 **/
460 UINT8
461 Tpm2GetIdleByPass (
462 IN VOID *Register
463 )
464 {
465 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;
466
467 //
468 // Check interface id
469 //
470 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);
471
472 return (UINT8)(InterfaceId.Bits.CapCRBIdleBypass);
473 }
474
475 /**
476 Dump PTP register information.
477
478 @param[in] Register Pointer to PTP register.
479 **/
480 VOID
481 DumpPtpInfo (
482 IN VOID *Register
483 )
484 {
485 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;
486 PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability;
487 UINT8 StatusEx;
488 UINT16 Vid;
489 UINT16 Did;
490 UINT8 Rid;
491 TPM2_PTP_INTERFACE_TYPE PtpInterface;
492
493 if (!Tpm2IsPtpPresence (Register)) {
494 return;
495 }
496
497 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);
498 InterfaceCapability.Uint32 = MmioRead32 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->InterfaceCapability);
499 StatusEx = MmioRead8 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->StatusEx);
500
501 //
502 // Dump InterfaceId Register for PTP
503 //
504 DEBUG ((DEBUG_INFO, "InterfaceId - 0x%08x\n", InterfaceId.Uint32));
505 DEBUG ((DEBUG_INFO, " InterfaceType - 0x%02x\n", InterfaceId.Bits.InterfaceType));
506 if (InterfaceId.Bits.InterfaceType != PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_TIS) {
507 DEBUG ((DEBUG_INFO, " InterfaceVersion - 0x%02x\n", InterfaceId.Bits.InterfaceVersion));
508 DEBUG ((DEBUG_INFO, " CapFIFO - 0x%x\n", InterfaceId.Bits.CapFIFO));
509 DEBUG ((DEBUG_INFO, " CapCRB - 0x%x\n", InterfaceId.Bits.CapCRB));
510 }
511
512 //
513 // Dump Capability Register for TIS and FIFO
514 //
515 DEBUG ((DEBUG_INFO, "InterfaceCapability - 0x%08x\n", InterfaceCapability.Uint32));
516 if ((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_TIS) ||
517 (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO))
518 {
519 DEBUG ((DEBUG_INFO, " InterfaceVersion - 0x%x\n", InterfaceCapability.Bits.InterfaceVersion));
520 }
521
522 //
523 // Dump StatusEx Register for PTP FIFO
524 //
525 DEBUG ((DEBUG_INFO, "StatusEx - 0x%02x\n", StatusEx));
526 if (InterfaceCapability.Bits.InterfaceVersion == INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP) {
527 DEBUG ((DEBUG_INFO, " TpmFamily - 0x%x\n", (StatusEx & PTP_FIFO_STS_EX_TPM_FAMILY) >> PTP_FIFO_STS_EX_TPM_FAMILY_OFFSET));
528 }
529
530 Vid = 0xFFFF;
531 Did = 0xFFFF;
532 Rid = 0xFF;
533 PtpInterface = GetCachedPtpInterface ();
534 DEBUG ((DEBUG_INFO, "PtpInterface - %x\n", PtpInterface));
535 switch (PtpInterface) {
536 case Tpm2PtpInterfaceCrb:
537 Vid = MmioRead16 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->Vid);
538 Did = MmioRead16 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->Did);
539 Rid = (UINT8)InterfaceId.Bits.Rid;
540 break;
541 case Tpm2PtpInterfaceFifo:
542 case Tpm2PtpInterfaceTis:
543 Vid = MmioRead16 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->Vid);
544 Did = MmioRead16 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->Did);
545 Rid = MmioRead8 ((UINTN)&((PTP_FIFO_REGISTERS *)Register)->Rid);
546 break;
547 default:
548 break;
549 }
550
551 DEBUG ((DEBUG_INFO, "VID - 0x%04x\n", Vid));
552 DEBUG ((DEBUG_INFO, "DID - 0x%04x\n", Did));
553 DEBUG ((DEBUG_INFO, "RID - 0x%02x\n", Rid));
554 }
555
556 /**
557 This service enables the sending of commands to the TPM2.
558
559 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
560 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
561 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
562 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
563
564 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
565 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
566 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
567 **/
568 EFI_STATUS
569 EFIAPI
570 DTpm2SubmitCommand (
571 IN UINT32 InputParameterBlockSize,
572 IN UINT8 *InputParameterBlock,
573 IN OUT UINT32 *OutputParameterBlockSize,
574 IN UINT8 *OutputParameterBlock
575 )
576 {
577 TPM2_PTP_INTERFACE_TYPE PtpInterface;
578
579 PtpInterface = GetCachedPtpInterface ();
580 switch (PtpInterface) {
581 case Tpm2PtpInterfaceCrb:
582 return PtpCrbTpmCommand (
583 (PTP_CRB_REGISTERS_PTR)(UINTN)PcdGet64 (PcdTpmBaseAddress),
584 InputParameterBlock,
585 InputParameterBlockSize,
586 OutputParameterBlock,
587 OutputParameterBlockSize
588 );
589 case Tpm2PtpInterfaceFifo:
590 case Tpm2PtpInterfaceTis:
591 return Tpm2TisTpmCommand (
592 (TIS_PC_REGISTERS_PTR)(UINTN)PcdGet64 (PcdTpmBaseAddress),
593 InputParameterBlock,
594 InputParameterBlockSize,
595 OutputParameterBlock,
596 OutputParameterBlockSize
597 );
598 default:
599 return EFI_NOT_FOUND;
600 }
601 }
602
603 /**
604 This service requests use TPM2.
605
606 @retval EFI_SUCCESS Get the control of TPM2 chip.
607 @retval EFI_NOT_FOUND TPM2 not found.
608 @retval EFI_DEVICE_ERROR Unexpected device behavior.
609 **/
610 EFI_STATUS
611 EFIAPI
612 DTpm2RequestUseTpm (
613 VOID
614 )
615 {
616 TPM2_PTP_INTERFACE_TYPE PtpInterface;
617
618 PtpInterface = GetCachedPtpInterface ();
619 switch (PtpInterface) {
620 case Tpm2PtpInterfaceCrb:
621 return PtpCrbRequestUseTpm ((PTP_CRB_REGISTERS_PTR)(UINTN)PcdGet64 (PcdTpmBaseAddress));
622 case Tpm2PtpInterfaceFifo:
623 case Tpm2PtpInterfaceTis:
624 return TisPcRequestUseTpm ((TIS_PC_REGISTERS_PTR)(UINTN)PcdGet64 (PcdTpmBaseAddress));
625 default:
626 return EFI_NOT_FOUND;
627 }
628 }