]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.c
f975b1bc8aaba915225d1c47957251281f739b3a
[mirror_edk2.git] / SecurityPkg / Library / Tpm12DeviceLibTcg / Tpm12DeviceLibTcg.c
1 /** @file
2 This library is TPM12 TCG protocol lib.
3
4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Uefi.h>
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/UefiBootServicesTableLib.h>
14 #include <Library/Tpm12DeviceLib.h>
15 #include <Protocol/TcgService.h>
16 #include <IndustryStandard/Tpm12.h>
17
18 EFI_TCG_PROTOCOL *mTcgProtocol = NULL;
19
20 /**
21 This service enables the sending of commands to the TPM12.
22
23 @param[in] InputParameterBlockSize Size of the TPM12 input parameter block.
24 @param[in] InputParameterBlock Pointer to the TPM12 input parameter block.
25 @param[in,out] OutputParameterBlockSize Size of the TPM12 output parameter block.
26 @param[in] OutputParameterBlock Pointer to the TPM12 output parameter block.
27
28 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
29 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
30 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
31 **/
32 EFI_STATUS
33 EFIAPI
34 Tpm12SubmitCommand (
35 IN UINT32 InputParameterBlockSize,
36 IN UINT8 *InputParameterBlock,
37 IN OUT UINT32 *OutputParameterBlockSize,
38 IN UINT8 *OutputParameterBlock
39 )
40 {
41 EFI_STATUS Status;
42 TPM_RSP_COMMAND_HDR *Header;
43
44 if (mTcgProtocol == NULL) {
45 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &mTcgProtocol);
46 if (EFI_ERROR (Status)) {
47 //
48 // TCG protocol is not installed. So, TPM12 is not present.
49 //
50 DEBUG ((EFI_D_ERROR, "Tpm12SubmitCommand - TCG - %r\n", Status));
51 return EFI_NOT_FOUND;
52 }
53 }
54 //
55 // Assume when TCG Protocol is ready, RequestUseTpm already done.
56 //
57 Status = mTcgProtocol->PassThroughToTpm (
58 mTcgProtocol,
59 InputParameterBlockSize,
60 InputParameterBlock,
61 *OutputParameterBlockSize,
62 OutputParameterBlock
63 );
64 if (EFI_ERROR (Status)) {
65 return Status;
66 }
67 Header = (TPM_RSP_COMMAND_HDR *)OutputParameterBlock;
68 *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);
69
70 return EFI_SUCCESS;
71 }
72
73 /**
74 This service requests use TPM12.
75
76 @retval EFI_SUCCESS Get the control of TPM12 chip.
77 @retval EFI_NOT_FOUND TPM12 not found.
78 @retval EFI_DEVICE_ERROR Unexpected device behavior.
79 **/
80 EFI_STATUS
81 EFIAPI
82 Tpm12RequestUseTpm (
83 VOID
84 )
85 {
86 EFI_STATUS Status;
87
88 if (mTcgProtocol == NULL) {
89 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &mTcgProtocol);
90 if (EFI_ERROR (Status)) {
91 //
92 // TCG protocol is not installed. So, TPM12 is not present.
93 //
94 DEBUG ((EFI_D_ERROR, "Tpm12RequestUseTpm - TCG - %r\n", Status));
95 return EFI_NOT_FOUND;
96 }
97 }
98 //
99 // Assume when TCG Protocol is ready, RequestUseTpm already done.
100 //
101 return EFI_SUCCESS;
102 }