2 This library is TPM2 device router. Platform can register multi TPM2 instance to it
3 via PcdTpmInstanceGuid. Platform need make choice that which one will be final one.
4 At most one TPM2 instance can be finally registered, and other will return unsupported.
6 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/HobLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/PcdLib.h>
16 #include <Library/Tpm2DeviceLib.h>
18 EFI_GUID mInternalTpm2DeviceInterfaceGuid
= {
19 0x349cf818, 0xc0ba, 0x4c43, { 0x92, 0x9a, 0xc8, 0xa1, 0xb1, 0xb3, 0xd2, 0x55 }
23 This function get TPM2.0 interface.
25 @retval TPM2.0 interface.
27 TPM2_DEVICE_INTERFACE
*
28 InternalGetTpm2DeviceInterface (
32 EFI_HOB_GUID_TYPE
*Hob
;
34 Hob
= GetFirstGuidHob (&mInternalTpm2DeviceInterfaceGuid
);
39 return (TPM2_DEVICE_INTERFACE
*)(Hob
+ 1);
43 This service enables the sending of commands to the TPM2.
45 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
46 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
47 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
48 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
50 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
51 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
52 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
57 IN UINT32 InputParameterBlockSize
,
58 IN UINT8
*InputParameterBlock
,
59 IN OUT UINT32
*OutputParameterBlockSize
,
60 IN UINT8
*OutputParameterBlock
63 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
65 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
66 if (Tpm2DeviceInterface
== NULL
) {
67 return EFI_UNSUPPORTED
;
70 return Tpm2DeviceInterface
->Tpm2SubmitCommand (
71 InputParameterBlockSize
,
73 OutputParameterBlockSize
,
79 This service requests use TPM2.
81 @retval EFI_SUCCESS Get the control of TPM2 chip.
82 @retval EFI_NOT_FOUND TPM2 not found.
83 @retval EFI_DEVICE_ERROR Unexpected device behavior.
91 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
93 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
94 if (Tpm2DeviceInterface
== NULL
) {
95 return EFI_UNSUPPORTED
;
98 return Tpm2DeviceInterface
->Tpm2RequestUseTpm ();
102 This service register TPM2 device.
104 @param Tpm2Device TPM2 device
106 @retval EFI_SUCCESS This TPM2 device is registered successfully.
107 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
108 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
112 Tpm2RegisterTpm2DeviceLib (
113 IN TPM2_DEVICE_INTERFACE
*Tpm2Device
116 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
118 if (!CompareGuid (PcdGetPtr (PcdTpmInstanceGuid
), &Tpm2Device
->ProviderGuid
)) {
119 DEBUG ((DEBUG_WARN
, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device
->ProviderGuid
));
120 return EFI_UNSUPPORTED
;
123 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
124 if (Tpm2DeviceInterface
!= NULL
) {
126 // In PEI phase, there will be shadow driver dispatched again.
128 DEBUG ((DEBUG_INFO
, "Tpm2RegisterTpm2DeviceLib - Override\n"));
129 CopyMem (Tpm2DeviceInterface
, Tpm2Device
, sizeof (*Tpm2Device
));
132 Tpm2Device
= BuildGuidDataHob (&mInternalTpm2DeviceInterfaceGuid
, Tpm2Device
, sizeof (*Tpm2Device
));
133 if (Tpm2Device
!= NULL
) {
136 return EFI_OUT_OF_RESOURCES
;