]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
SecurityPkg: Clean up source files
[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
63197670
ZC
37/**\r
38 Return PTP CRB interface IdleByPass state.\r
39\r
40 @param[in] Register Pointer to PTP register.\r
41\r
42 @return PTP CRB interface IdleByPass state.\r
43**/\r
44UINT8\r
45Tpm2GetIdleByPass (\r
46 IN VOID *Register\r
47 );\r
48\r
79e748cf
JY
49/**\r
50 Dump PTP register information.\r
51\r
52 @param[in] Register Pointer to PTP register.\r
53**/\r
54VOID\r
55DumpPtpInfo (\r
56 IN VOID *Register\r
57 );\r
58\r
c1d93242
JY
59/**\r
60 This service enables the sending of commands to the TPM2.\r
61\r
62 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r
63 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r
64 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r
65 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r
66\r
67 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r
68 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.\r
b3548d32 69 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r
c1d93242
JY
70**/\r
71EFI_STATUS\r
72EFIAPI\r
73DTpm2SubmitCommand (\r
74 IN UINT32 InputParameterBlockSize,\r
75 IN UINT8 *InputParameterBlock,\r
76 IN OUT UINT32 *OutputParameterBlockSize,\r
77 IN UINT8 *OutputParameterBlock\r
78 );\r
79\r
80/**\r
81 This service requests use TPM2.\r
82\r
83 @retval EFI_SUCCESS Get the control of TPM2 chip.\r
84 @retval EFI_NOT_FOUND TPM2 not found.\r
85 @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
86**/\r
87EFI_STATUS\r
88EFIAPI\r
89DTpm2RequestUseTpm (\r
90 VOID\r
91 );\r
92\r
93TPM2_DEVICE_INTERFACE mDTpm2InternalTpm2Device = {\r
94 TPM_DEVICE_INTERFACE_TPM20_DTPM,\r
95 DTpm2SubmitCommand,\r
96 DTpm2RequestUseTpm,\r
97};\r
98\r
99/**\r
f15cb995 100 The function register DTPM2.0 instance and caches current active TPM interface type.\r
b3548d32 101\r
c1d93242
JY
102 @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance\r
103**/\r
104EFI_STATUS\r
105EFIAPI\r
106Tpm2InstanceLibDTpmConstructor (\r
107 VOID\r
108 )\r
109{\r
f15cb995
ZC
110 EFI_STATUS Status;\r
111 TPM2_PTP_INTERFACE_TYPE PtpInterface;\r
63197670 112 UINT8 IdleByPass;\r
c1d93242
JY
113\r
114 Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);\r
115 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {\r
116 //\r
117 // Unsupported means platform policy does not need this instance enabled.\r
118 //\r
79e748cf 119 if (Status == EFI_SUCCESS) {\r
f15cb995
ZC
120 //\r
121 // Cache current active TpmInterfaceType only when needed\r
122 //\r
123 if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {\r
124 PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
125 PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);\r
126 }\r
63197670 127\r
975478f6 128 if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {\r
63197670
ZC
129 IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
130 PcdSet8S(PcdCRBIdleByPass, IdleByPass);\r
131 }\r
132\r
79e748cf
JY
133 DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r
134 }\r
c1d93242
JY
135 return EFI_SUCCESS;\r
136 }\r
137 return Status;\r
138}\r