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