]>
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 |
c1d93242 JY |
6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <Library/BaseLib.h>\r | |
17 | #include <Library/BaseMemoryLib.h>\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/Tpm2DeviceLib.h>\r | |
f15cb995 ZC |
20 | #include <Library/PcdLib.h>\r |
21 | \r | |
22 | /**\r | |
23 | Return PTP interface type.\r | |
24 | \r | |
25 | @param[in] Register Pointer to PTP register.\r | |
26 | \r | |
27 | @return PTP interface type.\r | |
28 | **/\r | |
29 | TPM2_PTP_INTERFACE_TYPE\r | |
30 | Tpm2GetPtpInterface (\r | |
31 | IN VOID *Register\r | |
32 | );\r | |
c1d93242 | 33 | \r |
63197670 ZC |
34 | /**\r |
35 | Return PTP CRB interface IdleByPass state.\r | |
36 | \r | |
37 | @param[in] Register Pointer to PTP register.\r | |
38 | \r | |
39 | @return PTP CRB interface IdleByPass state.\r | |
40 | **/\r | |
41 | UINT8\r | |
42 | Tpm2GetIdleByPass (\r | |
43 | IN VOID *Register\r | |
44 | );\r | |
45 | \r | |
c1d93242 JY |
46 | /**\r |
47 | This service enables the sending of commands to the TPM2.\r | |
48 | \r | |
49 | @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r | |
50 | @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r | |
51 | @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r | |
52 | @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r | |
53 | \r | |
54 | @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r | |
55 | @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 | 56 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r |
c1d93242 JY |
57 | **/\r |
58 | EFI_STATUS\r | |
59 | EFIAPI\r | |
60 | DTpm2SubmitCommand (\r | |
61 | IN UINT32 InputParameterBlockSize,\r | |
62 | IN UINT8 *InputParameterBlock,\r | |
63 | IN OUT UINT32 *OutputParameterBlockSize,\r | |
64 | IN UINT8 *OutputParameterBlock\r | |
65 | );\r | |
66 | \r | |
67 | /**\r | |
68 | This service requests use TPM2.\r | |
69 | \r | |
70 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
71 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
72 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
73 | **/\r | |
74 | EFI_STATUS\r | |
75 | EFIAPI\r | |
76 | DTpm2RequestUseTpm (\r | |
77 | VOID\r | |
78 | );\r | |
79 | \r | |
80 | /**\r | |
81 | This service enables the sending of commands to the TPM2.\r | |
82 | \r | |
83 | @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r | |
84 | @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r | |
85 | @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r | |
86 | @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r | |
87 | \r | |
88 | @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r | |
89 | @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 | 90 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r |
c1d93242 JY |
91 | **/\r |
92 | EFI_STATUS\r | |
93 | EFIAPI\r | |
94 | Tpm2SubmitCommand (\r | |
95 | IN UINT32 InputParameterBlockSize,\r | |
96 | IN UINT8 *InputParameterBlock,\r | |
97 | IN OUT UINT32 *OutputParameterBlockSize,\r | |
98 | IN UINT8 *OutputParameterBlock\r | |
99 | )\r | |
100 | {\r | |
101 | return DTpm2SubmitCommand (\r | |
102 | InputParameterBlockSize,\r | |
103 | InputParameterBlock,\r | |
104 | OutputParameterBlockSize,\r | |
105 | OutputParameterBlock\r | |
106 | );\r | |
107 | }\r | |
108 | \r | |
109 | /**\r | |
110 | This service requests use TPM2.\r | |
111 | \r | |
112 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
113 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
114 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
115 | **/\r | |
116 | EFI_STATUS\r | |
117 | EFIAPI\r | |
118 | Tpm2RequestUseTpm (\r | |
119 | VOID\r | |
120 | )\r | |
121 | {\r | |
122 | return DTpm2RequestUseTpm ();\r | |
123 | }\r | |
124 | \r | |
125 | /**\r | |
126 | This service register TPM2 device.\r | |
127 | \r | |
128 | @param Tpm2Device TPM2 device\r | |
129 | \r | |
130 | @retval EFI_SUCCESS This TPM2 device is registered successfully.\r | |
131 | @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r | |
132 | @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r | |
133 | **/\r | |
134 | EFI_STATUS\r | |
135 | EFIAPI\r | |
136 | Tpm2RegisterTpm2DeviceLib (\r | |
137 | IN TPM2_DEVICE_INTERFACE *Tpm2Device\r | |
138 | )\r | |
139 | {\r | |
140 | return EFI_UNSUPPORTED;\r | |
141 | }\r | |
f15cb995 ZC |
142 | \r |
143 | /**\r | |
144 | The function caches current active TPM interface type.\r | |
b3548d32 | 145 | \r |
f15cb995 ZC |
146 | @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance\r |
147 | **/\r | |
148 | EFI_STATUS\r | |
149 | EFIAPI\r | |
150 | Tpm2DeviceLibConstructor (\r | |
151 | VOID\r | |
152 | )\r | |
153 | {\r | |
154 | TPM2_PTP_INTERFACE_TYPE PtpInterface;\r | |
63197670 | 155 | UINT8 IdleByPass;\r |
f15cb995 ZC |
156 | \r |
157 | //\r | |
158 | // Cache current active TpmInterfaceType only when needed\r | |
159 | //\r | |
160 | if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {\r | |
161 | PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r | |
162 | PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);\r | |
163 | }\r | |
63197670 | 164 | \r |
975478f6 | 165 | if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {\r |
63197670 ZC |
166 | IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r |
167 | PcdSet8S(PcdCRBIdleByPass, IdleByPass);\r | |
168 | }\r | |
169 | \r | |
f15cb995 ZC |
170 | return EFI_SUCCESS;\r |
171 | }\r |