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