2 This library is TPM2 TCG2 protocol lib.
4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/BaseLib.h>
10 #include <Library/BaseMemoryLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Library/Tpm2DeviceLib.h>
14 #include <Protocol/Tcg2Protocol.h>
15 #include <IndustryStandard/Tpm20.h>
17 EFI_TCG2_PROTOCOL
*mTcg2Protocol
= NULL
;
20 This service enables the sending of commands to the TPM2.
22 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
23 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
24 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
25 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
27 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
28 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
29 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
34 IN UINT32 InputParameterBlockSize
,
35 IN UINT8
*InputParameterBlock
,
36 IN OUT UINT32
*OutputParameterBlockSize
,
37 IN UINT8
*OutputParameterBlock
41 TPM2_RESPONSE_HEADER
*Header
;
43 if (mTcg2Protocol
== NULL
) {
44 Status
= gBS
->LocateProtocol (&gEfiTcg2ProtocolGuid
, NULL
, (VOID
**) &mTcg2Protocol
);
45 if (EFI_ERROR (Status
)) {
47 // Tcg2 protocol is not installed. So, TPM2 is not present.
49 DEBUG ((DEBUG_ERROR
, "Tpm2SubmitCommand - Tcg2 - %r\n", Status
));
54 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.
56 Status
= mTcg2Protocol
->SubmitCommand (
58 InputParameterBlockSize
,
60 *OutputParameterBlockSize
,
63 if (EFI_ERROR (Status
)) {
66 Header
= (TPM2_RESPONSE_HEADER
*)OutputParameterBlock
;
67 *OutputParameterBlockSize
= SwapBytes32 (Header
->paramSize
);
73 This service requests use TPM2.
75 @retval EFI_SUCCESS Get the control of TPM2 chip.
76 @retval EFI_NOT_FOUND TPM2 not found.
77 @retval EFI_DEVICE_ERROR Unexpected device behavior.
87 if (mTcg2Protocol
== NULL
) {
88 Status
= gBS
->LocateProtocol (&gEfiTcg2ProtocolGuid
, NULL
, (VOID
**) &mTcg2Protocol
);
89 if (EFI_ERROR (Status
)) {
91 // Tcg2 protocol is not installed. So, TPM2 is not present.
93 DEBUG ((DEBUG_ERROR
, "Tpm2RequestUseTpm - Tcg2 - %r\n", Status
));
98 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.
104 This service register TPM2 device.
106 @param Tpm2Device TPM2 device
108 @retval EFI_SUCCESS This TPM2 device is registered successfully.
109 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
110 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
114 Tpm2RegisterTpm2DeviceLib (
115 IN TPM2_DEVICE_INTERFACE
*Tpm2Device
118 return EFI_UNSUPPORTED
;