]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
c411b485
MK
34 IN UINT32 InputParameterBlockSize,\r
35 IN UINT8 *InputParameterBlock,\r
36 IN OUT UINT32 *OutputParameterBlockSize,\r
37 IN UINT8 *OutputParameterBlock\r
1abfa4ce
JY
38 )\r
39{\r
c411b485
MK
40 EFI_STATUS Status;\r
41 TPM2_RESPONSE_HEADER *Header;\r
1abfa4ce
JY
42\r
43 if (mTcg2Protocol == NULL) {\r
c411b485 44 Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **)&mTcg2Protocol);\r
1abfa4ce
JY
45 if (EFI_ERROR (Status)) {\r
46 //\r
47 // Tcg2 protocol is not installed. So, TPM2 is not present.\r
48 //\r
e905fbb0 49 DEBUG ((DEBUG_ERROR, "Tpm2SubmitCommand - Tcg2 - %r\n", Status));\r
1abfa4ce
JY
50 return EFI_NOT_FOUND;\r
51 }\r
52 }\r
c411b485 53\r
1abfa4ce
JY
54 //\r
55 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.\r
56 //\r
57 Status = mTcg2Protocol->SubmitCommand (\r
58 mTcg2Protocol,\r
59 InputParameterBlockSize,\r
60 InputParameterBlock,\r
61 *OutputParameterBlockSize,\r
62 OutputParameterBlock\r
63 );\r
64 if (EFI_ERROR (Status)) {\r
65 return Status;\r
66 }\r
c411b485
MK
67\r
68 Header = (TPM2_RESPONSE_HEADER *)OutputParameterBlock;\r
1abfa4ce
JY
69 *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);\r
70\r
71 return EFI_SUCCESS;\r
72}\r
73\r
74/**\r
75 This service requests use TPM2.\r
76\r
77 @retval EFI_SUCCESS Get the control of TPM2 chip.\r
78 @retval EFI_NOT_FOUND TPM2 not found.\r
79 @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
80**/\r
81EFI_STATUS\r
82EFIAPI\r
83Tpm2RequestUseTpm (\r
84 VOID\r
85 )\r
86{\r
c411b485 87 EFI_STATUS Status;\r
1abfa4ce
JY
88\r
89 if (mTcg2Protocol == NULL) {\r
c411b485 90 Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **)&mTcg2Protocol);\r
1abfa4ce
JY
91 if (EFI_ERROR (Status)) {\r
92 //\r
93 // Tcg2 protocol is not installed. So, TPM2 is not present.\r
94 //\r
e905fbb0 95 DEBUG ((DEBUG_ERROR, "Tpm2RequestUseTpm - Tcg2 - %r\n", Status));\r
1abfa4ce
JY
96 return EFI_NOT_FOUND;\r
97 }\r
98 }\r
c411b485 99\r
1abfa4ce
JY
100 //\r
101 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.\r
102 //\r
103 return EFI_SUCCESS;\r
104}\r
105\r
106/**\r
107 This service register TPM2 device.\r
108\r
109 @param Tpm2Device TPM2 device\r
110\r
111 @retval EFI_SUCCESS This TPM2 device is registered successfully.\r
112 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r
113 @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r
114**/\r
115EFI_STATUS\r
116EFIAPI\r
117Tpm2RegisterTpm2DeviceLib (\r
c411b485 118 IN TPM2_DEVICE_INTERFACE *Tpm2Device\r
1abfa4ce
JY
119 )\r
120{\r
121 return EFI_UNSUPPORTED;\r
122}\r