]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
3feb64df7edfde5f1c0ac987f7e69018980818e6
[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 This service enables the sending of commands to the TPM2.
36
37 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
38 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
39 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
40 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
41
42 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
43 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
44 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
45 **/
46 EFI_STATUS
47 EFIAPI
48 DTpm2SubmitCommand (
49 IN UINT32 InputParameterBlockSize,
50 IN UINT8 *InputParameterBlock,
51 IN OUT UINT32 *OutputParameterBlockSize,
52 IN UINT8 *OutputParameterBlock
53 );
54
55 /**
56 This service requests use TPM2.
57
58 @retval EFI_SUCCESS Get the control of TPM2 chip.
59 @retval EFI_NOT_FOUND TPM2 not found.
60 @retval EFI_DEVICE_ERROR Unexpected device behavior.
61 **/
62 EFI_STATUS
63 EFIAPI
64 DTpm2RequestUseTpm (
65 VOID
66 );
67
68 /**
69 This service enables the sending of commands to the TPM2.
70
71 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
72 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
73 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
74 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
75
76 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
77 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
78 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
79 **/
80 EFI_STATUS
81 EFIAPI
82 Tpm2SubmitCommand (
83 IN UINT32 InputParameterBlockSize,
84 IN UINT8 *InputParameterBlock,
85 IN OUT UINT32 *OutputParameterBlockSize,
86 IN UINT8 *OutputParameterBlock
87 )
88 {
89 return DTpm2SubmitCommand (
90 InputParameterBlockSize,
91 InputParameterBlock,
92 OutputParameterBlockSize,
93 OutputParameterBlock
94 );
95 }
96
97 /**
98 This service requests use TPM2.
99
100 @retval EFI_SUCCESS Get the control of TPM2 chip.
101 @retval EFI_NOT_FOUND TPM2 not found.
102 @retval EFI_DEVICE_ERROR Unexpected device behavior.
103 **/
104 EFI_STATUS
105 EFIAPI
106 Tpm2RequestUseTpm (
107 VOID
108 )
109 {
110 return DTpm2RequestUseTpm ();
111 }
112
113 /**
114 This service register TPM2 device.
115
116 @param Tpm2Device TPM2 device
117
118 @retval EFI_SUCCESS This TPM2 device is registered successfully.
119 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
120 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
121 **/
122 EFI_STATUS
123 EFIAPI
124 Tpm2RegisterTpm2DeviceLib (
125 IN TPM2_DEVICE_INTERFACE *Tpm2Device
126 )
127 {
128 return EFI_UNSUPPORTED;
129 }
130
131 /**
132 The function caches current active TPM interface type.
133
134 @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance
135 **/
136 EFI_STATUS
137 EFIAPI
138 Tpm2DeviceLibConstructor (
139 VOID
140 )
141 {
142 TPM2_PTP_INTERFACE_TYPE PtpInterface;
143
144 //
145 // Cache current active TpmInterfaceType only when needed
146 //
147 if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
148 PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
149 PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
150 }
151 return EFI_SUCCESS;
152 }