]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
SecurityPkg: Cache TPM interface type info
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2InstanceLibDTpm.c
CommitLineData
c1d93242 1/** @file\r
07309c3d 2 This library is TPM2 DTPM instance.\r
c1d93242
JY
3 It can be registered to Tpm2 Device router, to be active TPM2 engine,\r
4 based on platform setting.\r
5\r
f15cb995 6Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
c1d93242
JY
7This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <Library/BaseLib.h>\r
18#include <Library/BaseMemoryLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/Tpm2DeviceLib.h>\r
f15cb995 21#include <Library/PcdLib.h>\r
c1d93242
JY
22\r
23#include <Guid/TpmInstance.h>\r
24\r
f15cb995
ZC
25/**\r
26 Return PTP interface type.\r
27\r
28 @param[in] Register Pointer to PTP register.\r
29\r
30 @return PTP interface type.\r
31**/\r
32TPM2_PTP_INTERFACE_TYPE\r
33Tpm2GetPtpInterface (\r
34 IN VOID *Register\r
35 );\r
36\r
79e748cf
JY
37/**\r
38 Dump PTP register information.\r
39\r
40 @param[in] Register Pointer to PTP register.\r
41**/\r
42VOID\r
43DumpPtpInfo (\r
44 IN VOID *Register\r
45 );\r
46\r
c1d93242
JY
47/**\r
48 This service enables the sending of commands to the TPM2.\r
49\r
50 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r
51 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r
52 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r
53 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r
54\r
55 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r
56 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.\r
57 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small. \r
58**/\r
59EFI_STATUS\r
60EFIAPI\r
61DTpm2SubmitCommand (\r
62 IN UINT32 InputParameterBlockSize,\r
63 IN UINT8 *InputParameterBlock,\r
64 IN OUT UINT32 *OutputParameterBlockSize,\r
65 IN UINT8 *OutputParameterBlock\r
66 );\r
67\r
68/**\r
69 This service requests use TPM2.\r
70\r
71 @retval EFI_SUCCESS Get the control of TPM2 chip.\r
72 @retval EFI_NOT_FOUND TPM2 not found.\r
73 @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
74**/\r
75EFI_STATUS\r
76EFIAPI\r
77DTpm2RequestUseTpm (\r
78 VOID\r
79 );\r
80\r
81TPM2_DEVICE_INTERFACE mDTpm2InternalTpm2Device = {\r
82 TPM_DEVICE_INTERFACE_TPM20_DTPM,\r
83 DTpm2SubmitCommand,\r
84 DTpm2RequestUseTpm,\r
85};\r
86\r
87/**\r
f15cb995 88 The function register DTPM2.0 instance and caches current active TPM interface type.\r
c1d93242
JY
89 \r
90 @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance\r
91**/\r
92EFI_STATUS\r
93EFIAPI\r
94Tpm2InstanceLibDTpmConstructor (\r
95 VOID\r
96 )\r
97{\r
f15cb995
ZC
98 EFI_STATUS Status;\r
99 TPM2_PTP_INTERFACE_TYPE PtpInterface;\r
c1d93242
JY
100\r
101 Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);\r
102 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {\r
103 //\r
104 // Unsupported means platform policy does not need this instance enabled.\r
105 //\r
79e748cf 106 if (Status == EFI_SUCCESS) {\r
f15cb995
ZC
107 //\r
108 // Cache current active TpmInterfaceType only when needed\r
109 //\r
110 if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {\r
111 PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
112 PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);\r
113 }\r
79e748cf
JY
114 DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
115 }\r
c1d93242
JY
116 return EFI_SUCCESS;\r
117 }\r
118 return Status;\r
119}\r