]>
Commit | Line | Data |
---|---|---|
c1d93242 | 1 | /** @file\r |
07309c3d | 2 | This library is TPM2 DTPM device lib.\r |
c1d93242 JY |
3 | Choosing this library means platform uses and only uses DTPM device as TPM2 engine.\r |
4 | \r | |
f15cb995 | 5 | Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r |
289b714b | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
c1d93242 JY |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #include <Library/BaseLib.h>\r | |
11 | #include <Library/BaseMemoryLib.h>\r | |
12 | #include <Library/DebugLib.h>\r | |
13 | #include <Library/Tpm2DeviceLib.h>\r | |
f15cb995 ZC |
14 | #include <Library/PcdLib.h>\r |
15 | \r | |
16 | /**\r | |
17 | Return PTP interface type.\r | |
18 | \r | |
19 | @param[in] Register Pointer to PTP register.\r | |
20 | \r | |
21 | @return PTP interface type.\r | |
22 | **/\r | |
23 | TPM2_PTP_INTERFACE_TYPE\r | |
24 | Tpm2GetPtpInterface (\r | |
25 | IN VOID *Register\r | |
26 | );\r | |
c1d93242 | 27 | \r |
63197670 ZC |
28 | /**\r |
29 | Return PTP CRB interface IdleByPass state.\r | |
30 | \r | |
31 | @param[in] Register Pointer to PTP register.\r | |
32 | \r | |
33 | @return PTP CRB interface IdleByPass state.\r | |
34 | **/\r | |
35 | UINT8\r | |
36 | Tpm2GetIdleByPass (\r | |
37 | IN VOID *Register\r | |
38 | );\r | |
39 | \r | |
c1d93242 JY |
40 | /**\r |
41 | This service enables the sending of commands to the TPM2.\r | |
42 | \r | |
43 | @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r | |
44 | @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r | |
45 | @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r | |
46 | @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r | |
47 | \r | |
48 | @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r | |
49 | @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 | 50 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r |
c1d93242 JY |
51 | **/\r |
52 | EFI_STATUS\r | |
53 | EFIAPI\r | |
54 | DTpm2SubmitCommand (\r | |
55 | IN UINT32 InputParameterBlockSize,\r | |
56 | IN UINT8 *InputParameterBlock,\r | |
57 | IN OUT UINT32 *OutputParameterBlockSize,\r | |
58 | IN UINT8 *OutputParameterBlock\r | |
59 | );\r | |
60 | \r | |
61 | /**\r | |
62 | This service requests use TPM2.\r | |
63 | \r | |
64 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
65 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
66 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
67 | **/\r | |
68 | EFI_STATUS\r | |
69 | EFIAPI\r | |
70 | DTpm2RequestUseTpm (\r | |
71 | VOID\r | |
72 | );\r | |
73 | \r | |
74 | /**\r | |
75 | This service enables the sending of commands to the TPM2.\r | |
76 | \r | |
77 | @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r | |
78 | @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r | |
79 | @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r | |
80 | @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r | |
81 | \r | |
82 | @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r | |
83 | @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 | 84 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r |
c1d93242 JY |
85 | **/\r |
86 | EFI_STATUS\r | |
87 | EFIAPI\r | |
88 | Tpm2SubmitCommand (\r | |
89 | IN UINT32 InputParameterBlockSize,\r | |
90 | IN UINT8 *InputParameterBlock,\r | |
91 | IN OUT UINT32 *OutputParameterBlockSize,\r | |
92 | IN UINT8 *OutputParameterBlock\r | |
93 | )\r | |
94 | {\r | |
95 | return DTpm2SubmitCommand (\r | |
96 | InputParameterBlockSize,\r | |
97 | InputParameterBlock,\r | |
98 | OutputParameterBlockSize,\r | |
99 | OutputParameterBlock\r | |
100 | );\r | |
101 | }\r | |
102 | \r | |
103 | /**\r | |
104 | This service requests use TPM2.\r | |
105 | \r | |
106 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
107 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
108 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
109 | **/\r | |
110 | EFI_STATUS\r | |
111 | EFIAPI\r | |
112 | Tpm2RequestUseTpm (\r | |
113 | VOID\r | |
114 | )\r | |
115 | {\r | |
116 | return DTpm2RequestUseTpm ();\r | |
117 | }\r | |
118 | \r | |
119 | /**\r | |
120 | This service register TPM2 device.\r | |
121 | \r | |
122 | @param Tpm2Device TPM2 device\r | |
123 | \r | |
124 | @retval EFI_SUCCESS This TPM2 device is registered successfully.\r | |
125 | @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r | |
126 | @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r | |
127 | **/\r | |
128 | EFI_STATUS\r | |
129 | EFIAPI\r | |
130 | Tpm2RegisterTpm2DeviceLib (\r | |
131 | IN TPM2_DEVICE_INTERFACE *Tpm2Device\r | |
132 | )\r | |
133 | {\r | |
134 | return EFI_UNSUPPORTED;\r | |
135 | }\r | |
f15cb995 ZC |
136 | \r |
137 | /**\r | |
138 | The function caches current active TPM interface type.\r | |
b3548d32 | 139 | \r |
f15cb995 ZC |
140 | @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance\r |
141 | **/\r | |
142 | EFI_STATUS\r | |
143 | EFIAPI\r | |
144 | Tpm2DeviceLibConstructor (\r | |
145 | VOID\r | |
146 | )\r | |
147 | {\r | |
148 | TPM2_PTP_INTERFACE_TYPE PtpInterface;\r | |
63197670 | 149 | UINT8 IdleByPass;\r |
f15cb995 ZC |
150 | \r |
151 | //\r | |
152 | // Cache current active TpmInterfaceType only when needed\r | |
153 | //\r | |
154 | if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {\r | |
155 | PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r | |
156 | PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);\r | |
157 | }\r | |
63197670 | 158 | \r |
975478f6 | 159 | if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {\r |
63197670 ZC |
160 | IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r |
161 | PcdSet8S(PcdCRBIdleByPass, IdleByPass);\r | |
162 | }\r | |
163 | \r | |
f15cb995 ZC |
164 | return EFI_SUCCESS;\r |
165 | }\r |