]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 ((DEBUG_ERROR, "Tpm12SubmitCommand - TCG - %r\n", Status));
51 return EFI_NOT_FOUND;
52 }
53 }
54
55 //
56 // Assume when TCG Protocol is ready, RequestUseTpm already done.
57 //
58 Status = mTcgProtocol->PassThroughToTpm (
59 mTcgProtocol,
60 InputParameterBlockSize,
61 InputParameterBlock,
62 *OutputParameterBlockSize,
63 OutputParameterBlock
64 );
65 if (EFI_ERROR (Status)) {
66 return Status;
67 }
68
69 Header = (TPM_RSP_COMMAND_HDR *)OutputParameterBlock;
70 *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);
71
72 return EFI_SUCCESS;
73 }
74
75 /**
76 This service requests use TPM12.
77
78 @retval EFI_SUCCESS Get the control of TPM12 chip.
79 @retval EFI_NOT_FOUND TPM12 not found.
80 @retval EFI_DEVICE_ERROR Unexpected device behavior.
81 **/
82 EFI_STATUS
83 EFIAPI
84 Tpm12RequestUseTpm (
85 VOID
86 )
87 {
88 EFI_STATUS Status;
89
90 if (mTcgProtocol == NULL) {
91 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&mTcgProtocol);
92 if (EFI_ERROR (Status)) {
93 //
94 // TCG protocol is not installed. So, TPM12 is not present.
95 //
96 DEBUG ((DEBUG_ERROR, "Tpm12RequestUseTpm - TCG - %r\n", Status));
97 return EFI_NOT_FOUND;
98 }
99 }
100
101 //
102 // Assume when TCG Protocol is ready, RequestUseTpm already done.
103 //
104 return EFI_SUCCESS;
105 }