ArmPkg: only attempt buildin MmCommunicationDxe for AArch64
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibTcg2 / Tpm2DeviceLibTcg2.c
CommitLineData
1abfa4ce 1/** @file\r
07309c3d 2 This library is TPM2 TCG2 protocol lib.\r
1abfa4ce 3\r
b3548d32 4Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
289b714b 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
1abfa4ce
JY
6\r
7**/\r
8\r
9#include <Library/BaseLib.h>\r
10#include <Library/BaseMemoryLib.h>\r
11#include <Library/DebugLib.h>\r
12#include <Library/UefiBootServicesTableLib.h>\r
13#include <Library/Tpm2DeviceLib.h>\r
14#include <Protocol/Tcg2Protocol.h>\r
15#include <IndustryStandard/Tpm20.h>\r
16\r
b3548d32 17EFI_TCG2_PROTOCOL *mTcg2Protocol = NULL;\r
1abfa4ce
JY
18\r
19/**\r
20 This service enables the sending of commands to the TPM2.\r
21\r
22 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r
23 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r
24 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r
25 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r
26\r
27 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r
28 @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 29 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r
1abfa4ce
JY
30**/\r
31EFI_STATUS\r
32EFIAPI\r
33Tpm2SubmitCommand (\r
34 IN UINT32 InputParameterBlockSize,\r
35 IN UINT8 *InputParameterBlock,\r
36 IN OUT UINT32 *OutputParameterBlockSize,\r
37 IN UINT8 *OutputParameterBlock\r
38 )\r
39{\r
40 EFI_STATUS Status;\r
41 TPM2_RESPONSE_HEADER *Header;\r
42\r
43 if (mTcg2Protocol == NULL) {\r
44 Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &mTcg2Protocol);\r
45 if (EFI_ERROR (Status)) {\r
46 //\r
47 // Tcg2 protocol is not installed. So, TPM2 is not present.\r
48 //\r
49 DEBUG ((EFI_D_ERROR, "Tpm2SubmitCommand - Tcg2 - %r\n", Status));\r
50 return EFI_NOT_FOUND;\r
51 }\r
52 }\r
53 //\r
54 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.\r
55 //\r
56 Status = mTcg2Protocol->SubmitCommand (\r
57 mTcg2Protocol,\r
58 InputParameterBlockSize,\r
59 InputParameterBlock,\r
60 *OutputParameterBlockSize,\r
61 OutputParameterBlock\r
62 );\r
63 if (EFI_ERROR (Status)) {\r
64 return Status;\r
65 }\r
66 Header = (TPM2_RESPONSE_HEADER *)OutputParameterBlock;\r
67 *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);\r
68\r
69 return EFI_SUCCESS;\r
70}\r
71\r
72/**\r
73 This service requests use TPM2.\r
74\r
75 @retval EFI_SUCCESS Get the control of TPM2 chip.\r
76 @retval EFI_NOT_FOUND TPM2 not found.\r
77 @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
78**/\r
79EFI_STATUS\r
80EFIAPI\r
81Tpm2RequestUseTpm (\r
82 VOID\r
83 )\r
84{\r
85 EFI_STATUS Status;\r
86\r
87 if (mTcg2Protocol == NULL) {\r
88 Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &mTcg2Protocol);\r
89 if (EFI_ERROR (Status)) {\r
90 //\r
91 // Tcg2 protocol is not installed. So, TPM2 is not present.\r
92 //\r
93 DEBUG ((EFI_D_ERROR, "Tpm2RequestUseTpm - Tcg2 - %r\n", Status));\r
94 return EFI_NOT_FOUND;\r
95 }\r
96 }\r
97 //\r
98 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.\r
99 //\r
100 return EFI_SUCCESS;\r
101}\r
102\r
103/**\r
104 This service register TPM2 device.\r
105\r
106 @param Tpm2Device TPM2 device\r
107\r
108 @retval EFI_SUCCESS This TPM2 device is registered successfully.\r
109 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r
110 @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r
111**/\r
112EFI_STATUS\r
113EFIAPI\r
114Tpm2RegisterTpm2DeviceLib (\r
115 IN TPM2_DEVICE_INTERFACE *Tpm2Device\r
116 )\r
117{\r
118 return EFI_UNSUPPORTED;\r
119}\r