2 Ihis 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 - 2014, Intel Corporation. All rights reserved. <BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/HobLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/Tpm2DeviceLib.h>
24 EFI_GUID mInternalTpm2DeviceInterfaceGuid
= {
25 0x349cf818, 0xc0ba, 0x4c43, { 0x92, 0x9a, 0xc8, 0xa1, 0xb1, 0xb3, 0xd2, 0x55 }
29 This function get TPM2.0 interface.
31 @retval TPM2.0 interface.
33 TPM2_DEVICE_INTERFACE
*
34 InternalGetTpm2DeviceInterface (
38 EFI_HOB_GUID_TYPE
*Hob
;
40 Hob
= GetFirstGuidHob (&mInternalTpm2DeviceInterfaceGuid
);
44 return (TPM2_DEVICE_INTERFACE
*)(Hob
+ 1);
48 This service enables the sending of commands to the TPM2.
50 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
51 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
52 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
53 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
55 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
56 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
57 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
62 IN UINT32 InputParameterBlockSize
,
63 IN UINT8
*InputParameterBlock
,
64 IN OUT UINT32
*OutputParameterBlockSize
,
65 IN UINT8
*OutputParameterBlock
68 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
70 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
71 if (Tpm2DeviceInterface
== NULL
) {
72 return EFI_UNSUPPORTED
;
75 return Tpm2DeviceInterface
->Tpm2SubmitCommand (
76 InputParameterBlockSize
,
78 OutputParameterBlockSize
,
84 This service requests use TPM2.
86 @retval EFI_SUCCESS Get the control of TPM2 chip.
87 @retval EFI_NOT_FOUND TPM2 not found.
88 @retval EFI_DEVICE_ERROR Unexpected device behavior.
96 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
98 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
99 if (Tpm2DeviceInterface
== NULL
) {
100 return EFI_UNSUPPORTED
;
102 return Tpm2DeviceInterface
->Tpm2RequestUseTpm ();
106 This service register TPM2 device.
108 @param Tpm2Device TPM2 device
110 @retval EFI_SUCCESS This TPM2 device is registered successfully.
111 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
112 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
116 Tpm2RegisterTpm2DeviceLib (
117 IN TPM2_DEVICE_INTERFACE
*Tpm2Device
120 TPM2_DEVICE_INTERFACE
*Tpm2DeviceInterface
;
122 if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &Tpm2Device
->ProviderGuid
)){
123 DEBUG ((EFI_D_ERROR
, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device
->ProviderGuid
));
124 return EFI_UNSUPPORTED
;
127 Tpm2DeviceInterface
= InternalGetTpm2DeviceInterface ();
128 if (Tpm2DeviceInterface
!= NULL
) {
130 // In PEI phase, there will be shadow driver dispatched again.
132 DEBUG ((EFI_D_INFO
, "Tpm2RegisterTpm2DeviceLib - Override\n"));
133 CopyMem (Tpm2DeviceInterface
, Tpm2Device
, sizeof(*Tpm2Device
));
136 Tpm2Device
= BuildGuidDataHob (&mInternalTpm2DeviceInterfaceGuid
, Tpm2Device
, sizeof(*Tpm2Device
));
137 if (Tpm2Device
!= NULL
) {
140 return EFI_OUT_OF_RESOURCES
;