Commit | Line | Data |
---|---|---|
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 | 6 | Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r |
c1d93242 JY |
7 | This program and the accompanying materials\r |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT 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 | |
32 | TPM2_PTP_INTERFACE_TYPE\r | |
33 | Tpm2GetPtpInterface (\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 | |
44 | UINT8\r | |
45 | Tpm2GetIdleByPass (\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 | |
54 | VOID\r | |
55 | DumpPtpInfo (\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 | |
69 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small. \r | |
70 | **/\r | |
71 | EFI_STATUS\r | |
72 | EFIAPI\r | |
73 | DTpm2SubmitCommand (\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 | |
87 | EFI_STATUS\r | |
88 | EFIAPI\r | |
89 | DTpm2RequestUseTpm (\r | |
90 | VOID\r | |
91 | );\r | |
92 | \r | |
93 | TPM2_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 |
c1d93242 JY |
101 | \r |
102 | @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance\r | |
103 | **/\r | |
104 | EFI_STATUS\r | |
105 | EFIAPI\r | |
106 | Tpm2InstanceLibDTpmConstructor (\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 ZC |
127 | \r |
128 | if (PcdGet8(PcdActiveTpmInterfaceType) == PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {\r | |
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 |