]>
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 |
289b714b | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
c1d93242 JY |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #include <Library/BaseLib.h>\r | |
12 | #include <Library/BaseMemoryLib.h>\r | |
13 | #include <Library/DebugLib.h>\r | |
14 | #include <Library/Tpm2DeviceLib.h>\r | |
f15cb995 | 15 | #include <Library/PcdLib.h>\r |
c1d93242 JY |
16 | \r |
17 | #include <Guid/TpmInstance.h>\r | |
18 | \r | |
f15cb995 ZC |
19 | /**\r |
20 | Return PTP interface type.\r | |
21 | \r | |
22 | @param[in] Register Pointer to PTP register.\r | |
23 | \r | |
24 | @return PTP interface type.\r | |
25 | **/\r | |
26 | TPM2_PTP_INTERFACE_TYPE\r | |
27 | Tpm2GetPtpInterface (\r | |
28 | IN VOID *Register\r | |
29 | );\r | |
30 | \r | |
63197670 ZC |
31 | /**\r |
32 | Return PTP CRB interface IdleByPass state.\r | |
33 | \r | |
34 | @param[in] Register Pointer to PTP register.\r | |
35 | \r | |
36 | @return PTP CRB interface IdleByPass state.\r | |
37 | **/\r | |
38 | UINT8\r | |
39 | Tpm2GetIdleByPass (\r | |
40 | IN VOID *Register\r | |
41 | );\r | |
42 | \r | |
79e748cf JY |
43 | /**\r |
44 | Dump PTP register information.\r | |
45 | \r | |
46 | @param[in] Register Pointer to PTP register.\r | |
47 | **/\r | |
48 | VOID\r | |
49 | DumpPtpInfo (\r | |
50 | IN VOID *Register\r | |
51 | );\r | |
52 | \r | |
c1d93242 JY |
53 | /**\r |
54 | This service enables the sending of commands to the TPM2.\r | |
55 | \r | |
56 | @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r | |
57 | @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r | |
58 | @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r | |
59 | @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r | |
60 | \r | |
61 | @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r | |
62 | @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 | 63 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r |
c1d93242 JY |
64 | **/\r |
65 | EFI_STATUS\r | |
66 | EFIAPI\r | |
67 | DTpm2SubmitCommand (\r | |
68 | IN UINT32 InputParameterBlockSize,\r | |
69 | IN UINT8 *InputParameterBlock,\r | |
70 | IN OUT UINT32 *OutputParameterBlockSize,\r | |
71 | IN UINT8 *OutputParameterBlock\r | |
72 | );\r | |
73 | \r | |
74 | /**\r | |
75 | This service requests use TPM2.\r | |
76 | \r | |
77 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
78 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
79 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
80 | **/\r | |
81 | EFI_STATUS\r | |
82 | EFIAPI\r | |
83 | DTpm2RequestUseTpm (\r | |
84 | VOID\r | |
85 | );\r | |
86 | \r | |
87 | TPM2_DEVICE_INTERFACE mDTpm2InternalTpm2Device = {\r | |
88 | TPM_DEVICE_INTERFACE_TPM20_DTPM,\r | |
89 | DTpm2SubmitCommand,\r | |
90 | DTpm2RequestUseTpm,\r | |
91 | };\r | |
92 | \r | |
93 | /**\r | |
f15cb995 | 94 | The function register DTPM2.0 instance and caches current active TPM interface type.\r |
b3548d32 | 95 | \r |
c1d93242 JY |
96 | @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance\r |
97 | **/\r | |
98 | EFI_STATUS\r | |
99 | EFIAPI\r | |
100 | Tpm2InstanceLibDTpmConstructor (\r | |
101 | VOID\r | |
102 | )\r | |
103 | {\r | |
f15cb995 ZC |
104 | EFI_STATUS Status;\r |
105 | TPM2_PTP_INTERFACE_TYPE PtpInterface;\r | |
63197670 | 106 | UINT8 IdleByPass;\r |
c1d93242 JY |
107 | \r |
108 | Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);\r | |
109 | if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {\r | |
110 | //\r | |
111 | // Unsupported means platform policy does not need this instance enabled.\r | |
112 | //\r | |
79e748cf | 113 | if (Status == EFI_SUCCESS) {\r |
f15cb995 ZC |
114 | //\r |
115 | // Cache current active TpmInterfaceType only when needed\r | |
116 | //\r | |
117 | if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {\r | |
118 | PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r | |
119 | PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);\r | |
120 | }\r | |
63197670 | 121 | \r |
975478f6 | 122 | if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {\r |
63197670 ZC |
123 | IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r |
124 | PcdSet8S(PcdCRBIdleByPass, IdleByPass);\r | |
125 | }\r | |
126 | \r | |
79e748cf JY |
127 | DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));\r |
128 | }\r | |
c1d93242 JY |
129 | return EFI_SUCCESS;\r |
130 | }\r | |
131 | return Status;\r | |
132 | }\r |