2 This library is TPM2 DTPM device lib.
3 Choosing this library means platform uses and only uses DTPM device as TPM2 engine.
5 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/Tpm2DeviceLib.h>
14 #include <Library/PcdLib.h>
17 Return PTP interface type.
19 @param[in] Register Pointer to PTP register.
21 @return PTP interface type.
23 TPM2_PTP_INTERFACE_TYPE
29 Return PTP CRB interface IdleByPass state.
31 @param[in] Register Pointer to PTP register.
33 @return PTP CRB interface IdleByPass state.
41 This service enables the sending of commands to the TPM2.
43 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
44 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
45 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
46 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
48 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
49 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
50 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
55 IN UINT32 InputParameterBlockSize
,
56 IN UINT8
*InputParameterBlock
,
57 IN OUT UINT32
*OutputParameterBlockSize
,
58 IN UINT8
*OutputParameterBlock
62 This service requests use TPM2.
64 @retval EFI_SUCCESS Get the control of TPM2 chip.
65 @retval EFI_NOT_FOUND TPM2 not found.
66 @retval EFI_DEVICE_ERROR Unexpected device behavior.
75 This service enables the sending of commands to the TPM2.
77 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
78 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
79 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
80 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
82 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
83 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
84 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
89 IN UINT32 InputParameterBlockSize
,
90 IN UINT8
*InputParameterBlock
,
91 IN OUT UINT32
*OutputParameterBlockSize
,
92 IN UINT8
*OutputParameterBlock
95 return DTpm2SubmitCommand (
96 InputParameterBlockSize
,
98 OutputParameterBlockSize
,
104 This service requests use TPM2.
106 @retval EFI_SUCCESS Get the control of TPM2 chip.
107 @retval EFI_NOT_FOUND TPM2 not found.
108 @retval EFI_DEVICE_ERROR Unexpected device behavior.
116 return DTpm2RequestUseTpm ();
120 This service register TPM2 device.
122 @param Tpm2Device TPM2 device
124 @retval EFI_SUCCESS This TPM2 device is registered successfully.
125 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
126 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
130 Tpm2RegisterTpm2DeviceLib (
131 IN TPM2_DEVICE_INTERFACE
*Tpm2Device
134 return EFI_UNSUPPORTED
;
138 The function caches current active TPM interface type.
140 @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance
144 Tpm2DeviceLibConstructor (
148 TPM2_PTP_INTERFACE_TYPE PtpInterface
;
152 // Cache current active TpmInterfaceType only when needed
154 if (PcdGet8(PcdActiveTpmInterfaceType
) == 0xFF) {
155 PtpInterface
= Tpm2GetPtpInterface ((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
156 PcdSet8S(PcdActiveTpmInterfaceType
, PtpInterface
);
159 if (PcdGet8(PcdActiveTpmInterfaceType
) == Tpm2PtpInterfaceCrb
&& PcdGet8(PcdCRBIdleByPass
) == 0xFF) {
160 IdleByPass
= Tpm2GetIdleByPass((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
161 PcdSet8S(PcdCRBIdleByPass
, IdleByPass
);