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
);
38 return (TPM2_DEVICE_INTERFACE
*)(Hob
+ 1);
42 This service enables the sending of commands to the TPM2.
44 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
45 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
46 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
47 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
49 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
50 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
51 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
56 IN UINT32 InputParameterBlockSize
,
57 IN UINT8
*InputParameterBlock
,
58 IN OUT UINT32
*OutputParameterBlockSize
,
59 IN UINT8
*OutputParameterBlock
62 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
64 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
65 if (Tpm2DeviceInterface
== NULL
) {
66 return EFI_UNSUPPORTED
;
69 return Tpm2DeviceInterface
->Tpm2SubmitCommand (
70 InputParameterBlockSize
,
72 OutputParameterBlockSize
,
78 This service requests use TPM2.
80 @retval EFI_SUCCESS Get the control of TPM2 chip.
81 @retval EFI_NOT_FOUND TPM2 not found.
82 @retval EFI_DEVICE_ERROR Unexpected device behavior.
90 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
92 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
93 if (Tpm2DeviceInterface
== NULL
) {
94 return EFI_UNSUPPORTED
;
96 return Tpm2DeviceInterface
->Tpm2RequestUseTpm ();
100 This service register TPM2 device.
102 @param Tpm2Device TPM2 device
104 @retval EFI_SUCCESS This TPM2 device is registered successfully.
105 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
106 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
110 Tpm2RegisterTpm2DeviceLib (
111 IN TPM2_DEVICE_INTERFACE
*Tpm2Device
114 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
116 if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &Tpm2Device
->ProviderGuid
)){
117 DEBUG ((DEBUG_WARN
, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device
->ProviderGuid
));
118 return EFI_UNSUPPORTED
;
121 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
122 if (Tpm2DeviceInterface
!= NULL
) {
124 // In PEI phase, there will be shadow driver dispatched again.
126 DEBUG ((EFI_D_INFO
, "Tpm2RegisterTpm2DeviceLib - Override\n"));
127 CopyMem (Tpm2DeviceInterface
, Tpm2Device
, sizeof(*Tpm2Device
));
130 Tpm2Device
= BuildGuidDataHob (&mInternalTpm2DeviceInterfaceGuid
, Tpm2Device
, sizeof(*Tpm2Device
));
131 if (Tpm2Device
!= NULL
) {
134 return EFI_OUT_OF_RESOURCES
;