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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/Tpm2DeviceLib.h>
20 #include <Library/PcdLib.h>
23 Return PTP interface type.
25 @param[in] Register Pointer to PTP register.
27 @return PTP interface type.
29 TPM2_PTP_INTERFACE_TYPE
35 Return PTP CRB interface IdleByPass state.
37 @param[in] Register Pointer to PTP register.
39 @return PTP CRB interface IdleByPass state.
47 This service enables the sending of commands to the TPM2.
49 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
50 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
51 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
52 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
54 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
55 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
56 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
61 IN UINT32 InputParameterBlockSize
,
62 IN UINT8
*InputParameterBlock
,
63 IN OUT UINT32
*OutputParameterBlockSize
,
64 IN UINT8
*OutputParameterBlock
68 This service requests use TPM2.
70 @retval EFI_SUCCESS Get the control of TPM2 chip.
71 @retval EFI_NOT_FOUND TPM2 not found.
72 @retval EFI_DEVICE_ERROR Unexpected device behavior.
81 This service enables the sending of commands to the TPM2.
83 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
84 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
85 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
86 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
88 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
89 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
90 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
95 IN UINT32 InputParameterBlockSize
,
96 IN UINT8
*InputParameterBlock
,
97 IN OUT UINT32
*OutputParameterBlockSize
,
98 IN UINT8
*OutputParameterBlock
101 return DTpm2SubmitCommand (
102 InputParameterBlockSize
,
104 OutputParameterBlockSize
,
110 This service requests use TPM2.
112 @retval EFI_SUCCESS Get the control of TPM2 chip.
113 @retval EFI_NOT_FOUND TPM2 not found.
114 @retval EFI_DEVICE_ERROR Unexpected device behavior.
122 return DTpm2RequestUseTpm ();
126 This service register TPM2 device.
128 @param Tpm2Device TPM2 device
130 @retval EFI_SUCCESS This TPM2 device is registered successfully.
131 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
132 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
136 Tpm2RegisterTpm2DeviceLib (
137 IN TPM2_DEVICE_INTERFACE
*Tpm2Device
140 return EFI_UNSUPPORTED
;
144 The function caches current active TPM interface type.
146 @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance
150 Tpm2DeviceLibConstructor (
154 TPM2_PTP_INTERFACE_TYPE PtpInterface
;
158 // Cache current active TpmInterfaceType only when needed
160 if (PcdGet8(PcdActiveTpmInterfaceType
) == 0xFF) {
161 PtpInterface
= Tpm2GetPtpInterface ((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
162 PcdSet8S(PcdActiveTpmInterfaceType
, PtpInterface
);
165 if (PcdGet8(PcdActiveTpmInterfaceType
) == PtpInterfaceCrb
&& PcdGet8(PcdCRBIdleByPass
) == 0xFF) {
166 IdleByPass
= Tpm2GetIdleByPass((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
167 PcdSet8S(PcdCRBIdleByPass
, IdleByPass
);