]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
SecurityPkg: Apply uncrustify changes
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2InstanceLibDTpm.c
CommitLineData
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 6Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
289b714b 7SPDX-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
7a56650e 19#include "Tpm2DeviceLibDTpm.h"\r
63197670 20\r
79e748cf
JY
21/**\r
22 Dump PTP register information.\r
23\r
24 @param[in] Register Pointer to PTP register.\r
25**/\r
26VOID\r
27DumpPtpInfo (\r
c411b485 28 IN VOID *Register\r
79e748cf
JY
29 );\r
30\r
c1d93242
JY
31/**\r
32 This service enables the sending of commands to the TPM2.\r
33\r
34 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r
35 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r
36 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r
37 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r
38\r
39 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r
40 @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 41 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r
c1d93242
JY
42**/\r
43EFI_STATUS\r
44EFIAPI\r
45DTpm2SubmitCommand (\r
c411b485
MK
46 IN UINT32 InputParameterBlockSize,\r
47 IN UINT8 *InputParameterBlock,\r
48 IN OUT UINT32 *OutputParameterBlockSize,\r
49 IN UINT8 *OutputParameterBlock\r
c1d93242
JY
50 );\r
51\r
52/**\r
53 This service requests use TPM2.\r
54\r
55 @retval EFI_SUCCESS Get the control of TPM2 chip.\r
56 @retval EFI_NOT_FOUND TPM2 not found.\r
57 @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
58**/\r
59EFI_STATUS\r
60EFIAPI\r
61DTpm2RequestUseTpm (\r
62 VOID\r
63 );\r
64\r
65TPM2_DEVICE_INTERFACE mDTpm2InternalTpm2Device = {\r
66 TPM_DEVICE_INTERFACE_TPM20_DTPM,\r
67 DTpm2SubmitCommand,\r
68 DTpm2RequestUseTpm,\r
69};\r
70\r
71/**\r
f15cb995 72 The function register DTPM2.0 instance and caches current active TPM interface type.\r
b3548d32 73\r
d6b926e7 74 @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance\r
c1d93242
JY
75**/\r
76EFI_STATUS\r
77EFIAPI\r
78Tpm2InstanceLibDTpmConstructor (\r
79 VOID\r
80 )\r
81{\r
c411b485 82 EFI_STATUS Status;\r
c1d93242
JY
83\r
84 Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);\r
85 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {\r
86 //\r
87 // Unsupported means platform policy does not need this instance enabled.\r
88 //\r
79e748cf 89 if (Status == EFI_SUCCESS) {\r
7a56650e 90 Status = InternalTpm2DeviceLibDTpmCommonConstructor ();\r
c411b485 91 DumpPtpInfo ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));\r
79e748cf 92 }\r
c411b485 93\r
c1d93242
JY
94 return EFI_SUCCESS;\r
95 }\r
c411b485 96\r
c1d93242
JY
97 return Status;\r
98}\r