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
));
55 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.
57 Status
= mTcg2Protocol
->SubmitCommand (
59 InputParameterBlockSize
,
61 *OutputParameterBlockSize
,
64 if (EFI_ERROR (Status
)) {
68 Header
= (TPM2_RESPONSE_HEADER
*)OutputParameterBlock
;
69 *OutputParameterBlockSize
= SwapBytes32 (Header
->paramSize
);
75 This service requests use TPM2.
77 @retval EFI_SUCCESS Get the control of TPM2 chip.
78 @retval EFI_NOT_FOUND TPM2 not found.
79 @retval EFI_DEVICE_ERROR Unexpected device behavior.
89 if (mTcg2Protocol
== NULL
) {
90 Status
= gBS
->LocateProtocol (&gEfiTcg2ProtocolGuid
, NULL
, (VOID
**)&mTcg2Protocol
);
91 if (EFI_ERROR (Status
)) {
93 // Tcg2 protocol is not installed. So, TPM2 is not present.
95 DEBUG ((DEBUG_ERROR
, "Tpm2RequestUseTpm - Tcg2 - %r\n", Status
));
101 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.
107 This service register TPM2 device.
109 @param Tpm2Device TPM2 device
111 @retval EFI_SUCCESS This TPM2 device is registered successfully.
112 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
113 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
117 Tpm2RegisterTpm2DeviceLib (
118 IN TPM2_DEVICE_INTERFACE
*Tpm2Device
121 return EFI_UNSUPPORTED
;