]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.c
SecurityPkg: Tcg2Dxe: Report correct FinalEventLog size
[mirror_edk2.git] / SecurityPkg / Library / Tpm12DeviceLibTcg / Tpm12DeviceLibTcg.c
CommitLineData
c1d93242 1/** @file\r
07309c3d 2 This library is TPM12 TCG protocol lib.\r
c1d93242 3\r
07309c3d 4Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>\r
c1d93242
JY
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Uefi.h>\r
16#include <Library/BaseLib.h>\r
17#include <Library/BaseMemoryLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/UefiBootServicesTableLib.h>\r
20#include <Library/Tpm12DeviceLib.h>\r
21#include <Protocol/TcgService.h>\r
22#include <IndustryStandard/Tpm12.h>\r
23\r
24EFI_TCG_PROTOCOL *mTcgProtocol = NULL; \r
25\r
26/**\r
27 This service enables the sending of commands to the TPM12.\r
28\r
29 @param[in] InputParameterBlockSize Size of the TPM12 input parameter block.\r
30 @param[in] InputParameterBlock Pointer to the TPM12 input parameter block.\r
31 @param[in,out] OutputParameterBlockSize Size of the TPM12 output parameter block.\r
32 @param[in] OutputParameterBlock Pointer to the TPM12 output parameter block.\r
33\r
34 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r
35 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.\r
36 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small. \r
37**/\r
38EFI_STATUS\r
39EFIAPI\r
40Tpm12SubmitCommand (\r
41 IN UINT32 InputParameterBlockSize,\r
42 IN UINT8 *InputParameterBlock,\r
43 IN OUT UINT32 *OutputParameterBlockSize,\r
44 IN UINT8 *OutputParameterBlock\r
45 )\r
46{\r
47 EFI_STATUS Status;\r
48 TPM_RSP_COMMAND_HDR *Header;\r
49\r
50 if (mTcgProtocol == NULL) {\r
51 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &mTcgProtocol);\r
52 if (EFI_ERROR (Status)) {\r
53 //\r
54 // TCG protocol is not installed. So, TPM12 is not present.\r
55 //\r
56 DEBUG ((EFI_D_ERROR, "Tpm12SubmitCommand - TCG - %r\n", Status));\r
57 return EFI_NOT_FOUND;\r
58 }\r
59 }\r
60 //\r
61 // Assume when TCG Protocol is ready, RequestUseTpm already done.\r
62 //\r
63 Status = mTcgProtocol->PassThroughToTpm (\r
64 mTcgProtocol,\r
65 InputParameterBlockSize,\r
66 InputParameterBlock,\r
67 *OutputParameterBlockSize,\r
68 OutputParameterBlock\r
69 );\r
70 if (EFI_ERROR (Status)) {\r
71 return Status;\r
72 }\r
73 Header = (TPM_RSP_COMMAND_HDR *)OutputParameterBlock;\r
74 *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);\r
75\r
76 return EFI_SUCCESS;\r
77}\r
78\r
79/**\r
80 This service requests use TPM12.\r
81\r
82 @retval EFI_SUCCESS Get the control of TPM12 chip.\r
83 @retval EFI_NOT_FOUND TPM12 not found.\r
84 @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
85**/\r
86EFI_STATUS\r
87EFIAPI\r
88Tpm12RequestUseTpm (\r
89 VOID\r
90 )\r
91{\r
92 EFI_STATUS Status;\r
93\r
94 if (mTcgProtocol == NULL) {\r
95 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &mTcgProtocol);\r
96 if (EFI_ERROR (Status)) {\r
97 //\r
98 // TCG protocol is not installed. So, TPM12 is not present.\r
99 //\r
100 DEBUG ((EFI_D_ERROR, "Tpm12RequestUseTpm - TCG - %r\n", Status));\r
101 return EFI_NOT_FOUND;\r
102 }\r
103 }\r
104 //\r
105 // Assume when TCG Protocol is ready, RequestUseTpm already done.\r
106 //\r
107 return EFI_SUCCESS;\r
108}\r